Skip to content

Commit

Permalink
Merge pull request #30 from gondor/master
Browse files Browse the repository at this point in the history
Add format options to application commands - lib compose fixes
  • Loading branch information
gondor committed Jun 1, 2016
2 parents f508eed + 6ea0347 commit d206409
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
20 changes: 15 additions & 5 deletions commands/marathon/app_cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
const (
HOST_FLAG = "host"
SCALE_FLAG = "scale"
FORMAT_FLAG = "format"
)

var appCmd = &cobra.Command{
Expand Down Expand Up @@ -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)
},
}

Expand All @@ -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)
},
}

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
}

26 changes: 14 additions & 12 deletions compose/compose_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io/ioutil"
"os"
"strings"
"github.com/docker/distribution/context"
)

const (
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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
Expand Down Expand Up @@ -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)
}

0 comments on commit d206409

Please sign in to comment.