diff --git a/commands/marathon/app_cmds.go b/commands/marathon/app_cmds.go index a4e7f5d..dabd166 100644 --- a/commands/marathon/app_cmds.go +++ b/commands/marathon/app_cmds.go @@ -17,6 +17,7 @@ import ( const ( HOST_FLAG = "host" SCALE_FLAG = "scale" + FORMAT_FLAG = "format" ) var appCmd = &cobra.Command{ @@ -56,7 +57,7 @@ var appListCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { v, e := client(cmd).ListApplications() - cli.Output(templateFor(T_APPLICATIONS, v), e) + cli.Output(templateFor(templateFormat(T_APPLICATIONS, cmd), v), e) }, } @@ -65,11 +66,8 @@ var appGetCmd = &cobra.Command{ Short: "Gets an application details by Id", Long: `Retrieves the specified [appliationId] application`, Run: func(cmd *cobra.Command, args []string) { - if cli.EvalPrintUsage(cmd.Usage, args, 1) { - return - } v, e := client(cmd).GetApplication(args[0]) - cli.Output(templateFor(T_APPLICATION, v), e) + cli.Output(templateFor(templateFormat(T_APPLICATION, cmd), v), e) }, } @@ -133,6 +131,8 @@ func init() { eg. -p MYVAR=value would replace ${MYVAR} with "value" in the application file. These take precidence over env vars`) + appListCmd.Flags().String(FORMAT_FLAG, "", "Custom output format. Example: '{{range .Apps}}{{ .Container.Docker.Image }}{{end}}'") + appGetCmd.Flags().String(FORMAT_FLAG, "", "Custom output format. Example: '{{ .ID }}'") applyCommonAppFlags(appCreateCmd, appUpdateCPUCmd, appUpdateMemoryCmd, appRollbackCmd, appDestroyCmd, appRestartCmd, appScaleCmd) } @@ -316,3 +316,13 @@ func applyCommonAppFlags(cmd ...*cobra.Command) { c.Flags().DurationP(TIMEOUT_FLAG, "t", time.Duration(0), "Max duration to wait for application health (ex. 90s | 2m). See docs for ordering") } } + +func templateFormat(template string, cmd *cobra.Command) string { + t := template + tv, _ := cmd.Flags().GetString(FORMAT_FLAG) + if len(tv) > 0 { + t = tv + } + return t +} + diff --git a/compose/compose_wrapper.go b/compose/compose_wrapper.go index 3c82352..1cea0c4 100644 --- a/compose/compose_wrapper.go +++ b/compose/compose_wrapper.go @@ -10,6 +10,7 @@ import ( "io/ioutil" "os" "strings" + "github.com/docker/distribution/context" ) const ( @@ -38,34 +39,34 @@ func NewCompose(context *Context) Compose { func (c *ComposeWrapper) Up(services ...string) error { options := options.Up{Create: options.Create{}} - return c.project.Up(options, services...) + return c.project.Up(context.Background(), options, services...) } func (c *ComposeWrapper) Kill(services ...string) error { - return c.project.Kill("SIGKILL", services...) + return c.project.Kill(context.Background(), "SIGKILL", services...) } func (c *ComposeWrapper) Build(services ...string) error { options := options.Build{} - return c.project.Build(options, services...) + return c.project.Build(context.Background(), options, services...) } func (c *ComposeWrapper) Restart(services ...string) error { timeout := 10 - return c.project.Restart(timeout, services...) + return c.project.Restart(context.Background(), timeout, services...) } func (c *ComposeWrapper) Pull(services ...string) error { - return c.project.Pull(services...) + return c.project.Pull(context.Background(), services...) } func (c *ComposeWrapper) Delete(services ...string) error { options := options.Delete{} - return c.project.Delete(options, services...) + return c.project.Delete(context.Background(), options, services...) } func (c *ComposeWrapper) Logs(services ...string) error { - return c.project.Log(true, services...) + return c.project.Log(context.Background(), true, services...) } func (c *ComposeWrapper) Start(services ...string) error { @@ -78,15 +79,15 @@ func (c *ComposeWrapper) Stop(services ...string) error { func (c *ComposeWrapper) execStartStop(start bool, services ...string) error { if start { - return c.project.Start(services...) + return c.project.Start(context.Background(), services...) } options := options.Down{} - return c.project.Down(options, services...) + return c.project.Down(context.Background(), options, services...) } func (c *ComposeWrapper) Port(index int, proto, service, port string) error { - output, err := c.project.Port(index, proto, service, port) + output, err := c.project.Port(context.Background(), index, proto, service, port) if err != nil { return err } @@ -95,7 +96,7 @@ func (c *ComposeWrapper) Port(index int, proto, service, port string) error { } func (c *ComposeWrapper) PS(quiet bool) error { - if allInfo, err := c.project.Ps(quiet); err == nil { + if allInfo, err := c.project.Ps(context.Background(), quiet); err == nil { os.Stdout.WriteString(allInfo.String(!quiet)) } return nil @@ -124,10 +125,11 @@ func (c *ComposeWrapper) createDockerContext() (project.APIProject, error) { } c.context.ComposeFile = file.Name() } + return docker.NewProject(&docker.Context{ Context: project.Context{ ComposeFiles: strings.Split(c.context.ComposeFile, ","), ProjectName: c.context.ProjectName, }, - }) + }, nil) }