diff --git a/tsuru/admin/app.go b/tsuru/admin/app.go index 34291c7f..6f4a016d 100644 --- a/tsuru/admin/app.go +++ b/tsuru/admin/app.go @@ -22,7 +22,7 @@ func (c *AppRoutesRebuild) Info() *cmd.Info { return &cmd.Info{ Name: "app-routes-rebuild", MinArgs: 0, - Usage: "app-routes-rebuild -a ", + Usage: "app-routes-rebuild ", Desc: `Rebuild routes for an application. This can be used to recover from some failure in the router that caused existing routes to be lost.`, @@ -30,7 +30,7 @@ existing routes to be lost.`, } func (c *AppRoutesRebuild) Run(ctx *cmd.Context) error { - appName, err := c.AppName() + appName, err := c.AppName(ctx.Args) if err != nil { return err } diff --git a/tsuru/admin/quota.go b/tsuru/admin/quota.go index 7d20815f..9b890b3c 100644 --- a/tsuru/admin/quota.go +++ b/tsuru/admin/quota.go @@ -100,7 +100,7 @@ func (*AppQuotaView) Info() *cmd.Info { return &cmd.Info{ Name: "app-quota-view", MinArgs: 0, - Usage: "app-quota-view [-a/--app appname]", + Usage: "app-quota-view [appname]", Desc: "Displays the current usage and limit of the given app.", } } @@ -117,7 +117,7 @@ func (c *AppQuotaView) Flags() *gnuflag.FlagSet { func (c *AppQuotaView) Run(context *cmd.Context) error { context.RawOutput() - appName, err := c.AppName() + appName, err := c.AppName(context.Args) if err != nil { return err } @@ -164,7 +164,7 @@ The new limit must be an integer, it may also be "unlimited".` func (c *AppQuotaChange) Run(context *cmd.Context) error { context.RawOutput() - appName, err := c.AppName() + appName, err := c.AppNameByFlag() if err != nil { return err } diff --git a/tsuru/admin/quota_test.go b/tsuru/admin/quota_test.go index 8b0ab2d5..d6cb89b6 100644 --- a/tsuru/admin/quota_test.go +++ b/tsuru/admin/quota_test.go @@ -170,7 +170,7 @@ func (s *S) TestAppQuotaViewRunFailure(c *check.C) { trans := cmdtest.Transport{Message: "app not found", Status: http.StatusNotFound} s.setupFakeTransport(&trans) command := AppQuotaView{} - command.Flags().Parse(true, []string{"--app", "hibria"}) + command.Flags().Parse(true, []string{}) err := command.Run(&context) c.Assert(err, check.NotNil) c.Assert(tsuruHTTP.UnwrapErr(err).Error(), check.Equals, "app not found") diff --git a/tsuru/app/app.go b/tsuru/app/app.go index 8c4356c4..c4dacae5 100644 --- a/tsuru/app/app.go +++ b/tsuru/app/app.go @@ -14,7 +14,19 @@ type AppNameMixIn struct { appName string } -func (cmd *AppNameMixIn) AppName() (string, error) { +func (cmd *AppNameMixIn) AppName(args []string) (string, error) { + if len(args) > 0 { + if cmd.appName != "" { + return "", errors.New("You can't use the app flag and specify the app name as an argument at the same time.") + } + + return args[0], nil + } + + return cmd.AppNameByFlag() +} + +func (cmd *AppNameMixIn) AppNameByFlag() (string, error) { if cmd.appName == "" { return "", errors.Errorf(`The name of the app is required. diff --git a/tsuru/app/app_test.go b/tsuru/app/app_test.go index 75c51514..12e116b2 100644 --- a/tsuru/app/app_test.go +++ b/tsuru/app/app_test.go @@ -34,7 +34,7 @@ var _ = check.Suite(&S{}) func (s *S) TestAppNameMixInWithFlagDefined(c *check.C) { g := AppNameMixIn{} g.Flags().Parse(true, []string{"--app", "myapp"}) - name, err := g.AppName() + name, err := g.AppNameByFlag() c.Assert(err, check.IsNil) c.Assert(name, check.Equals, "myapp") } @@ -42,14 +42,30 @@ func (s *S) TestAppNameMixInWithFlagDefined(c *check.C) { func (s *S) TestAppNameMixInWithShortFlagDefined(c *check.C) { g := AppNameMixIn{} g.Flags().Parse(true, []string{"-a", "myapp"}) - name, err := g.AppName() + name, err := g.AppNameByFlag() c.Assert(err, check.IsNil) c.Assert(name, check.Equals, "myapp") } +func (s *S) TestAppNameMixInArgs(c *check.C) { + g := AppNameMixIn{} + g.Flags().Parse(true, []string{}) + name, err := g.AppName([]string{"myapp"}) + c.Assert(err, check.IsNil) + c.Assert(name, check.Equals, "myapp") +} + +func (s *S) TestAppNameMixInArgsConflict(c *check.C) { + g := AppNameMixIn{} + g.Flags().Parse(true, []string{"-a", "myapp"}) + _, err := g.AppName([]string{"myapp2"}) + c.Assert(err, check.Not(check.IsNil)) + c.Assert(err.Error(), check.Equals, "You can't use the app flag and specify the app name as an argument at the same time.") +} + func (s *S) TestAppNameMixInWithoutFlagDefinedFails(c *check.C) { g := AppNameMixIn{} - name, err := g.AppName() + name, err := g.AppNameByFlag() c.Assert(name, check.Equals, "") c.Assert(err, check.NotNil) c.Assert(err.Error(), check.Equals, `The name of the app is required. diff --git a/tsuru/client/apps.go b/tsuru/client/apps.go index 0d6c8dad..5941cce5 100644 --- a/tsuru/client/apps.go +++ b/tsuru/client/apps.go @@ -397,7 +397,7 @@ type AppInfo struct { func (c *AppInfo) Info() *cmd.Info { return &cmd.Info{ Name: "app-info", - Usage: "app info [-a/--app appname]", + Usage: "app info [appname]", Desc: `Shows information about a specific app. Its state, platform, git repository, etc. You need to be a member of a team that has access to the app to be able to see information about it.`, @@ -418,7 +418,7 @@ func (cmd *AppInfo) Flags() *gnuflag.FlagSet { } func (c *AppInfo) Run(context *cmd.Context) error { - appName, err := c.AppName() + appName, err := c.AppName(context.Args) if err != nil { return err } @@ -1212,7 +1212,7 @@ app to a team.`, } func (c *AppGrant) Run(context *cmd.Context) error { - appName, err := c.AppName() + appName, err := c.AppNameByFlag() if err != nil { return err } @@ -1251,7 +1251,7 @@ authorized team.`, } func (c *AppRevoke) Run(context *cmd.Context) error { - appName, err := c.AppName() + appName, err := c.AppNameByFlag() if err != nil { return err } @@ -1470,7 +1470,7 @@ type AppStop struct { func (c *AppStop) Info() *cmd.Info { return &cmd.Info{ Name: "app-stop", - Usage: "app stop [-a/--app appname] [-p/--process processname] [--version version]", + Usage: "app stop [appname] [-p/--process processname] [--version version]", Desc: "Stops an application, or one of the processes of the application.", MinArgs: 0, } @@ -1478,7 +1478,7 @@ func (c *AppStop) Info() *cmd.Info { func (c *AppStop) Run(context *cmd.Context) error { context.RawOutput() - appName, err := c.AppName() + appName, err := c.AppName(context.Args) if err != nil { return err } @@ -1522,7 +1522,7 @@ type AppStart struct { func (c *AppStart) Info() *cmd.Info { return &cmd.Info{ Name: "app-start", - Usage: "app start [-a/--app appname] [-p/--process processname] [--version version]", + Usage: "app start [appname] [-p/--process processname] [--version version]", Desc: "Starts an application, or one of the processes of the application.", MinArgs: 0, } @@ -1530,7 +1530,7 @@ func (c *AppStart) Info() *cmd.Info { func (c *AppStart) Run(context *cmd.Context) error { context.RawOutput() - appName, err := c.AppName() + appName, err := c.AppName(context.Args) if err != nil { return err } @@ -1573,7 +1573,7 @@ type AppRestart struct { func (c *AppRestart) Run(context *cmd.Context) error { context.RawOutput() - appName, err := c.AppName() + appName, err := c.AppName(context.Args) if err != nil { return err } @@ -1600,7 +1600,7 @@ func (c *AppRestart) Run(context *cmd.Context) error { func (c *AppRestart) Info() *cmd.Info { return &cmd.Info{ Name: "app-restart", - Usage: "app restart [-a/--app appname] [-p/--process processname] [--version version]", + Usage: "app restart [appname] [-p/--process processname] [--version version]", Desc: `Restarts an application, or one of the processes of the application.`, MinArgs: 0, } @@ -1667,7 +1667,7 @@ After unsetting the CNAME from the app, [[tsuru app list]] and [[tsuru app info] } func unsetCName(cnames []string, g tsuruClientApp.AppNameMixIn) error { - appName, err := g.AppName() + appName, err := g.AppNameByFlag() if err != nil { return err } @@ -1688,7 +1688,7 @@ func unsetCName(cnames []string, g tsuruClientApp.AppNameMixIn) error { } func addCName(cnames []string, g tsuruClientApp.AppNameMixIn) error { - appName, err := g.AppName() + appName, err := g.AppNameByFlag() if err != nil { return err } diff --git a/tsuru/client/autoscale.go b/tsuru/client/autoscale.go index 26aeef6e..d1ff422a 100644 --- a/tsuru/client/autoscale.go +++ b/tsuru/client/autoscale.go @@ -86,7 +86,7 @@ func (c *AutoScaleSet) Run(ctx *cmd.Context) error { if err != nil { return err } - appName, err := c.AppName() + appName, err := c.AppNameByFlag() if err != nil { return err } @@ -153,7 +153,7 @@ func (c *AutoScaleUnset) Run(ctx *cmd.Context) error { if err != nil { return err } - appName, err := c.AppName() + appName, err := c.AppNameByFlag() if err != nil { return err } diff --git a/tsuru/client/build.go b/tsuru/client/build.go index d10053d5..4a3d9c48 100644 --- a/tsuru/client/build.go +++ b/tsuru/client/build.go @@ -78,7 +78,7 @@ func (c *AppBuild) Run(context *cmd.Context) error { return errors.New("You should provide at least one file to build the image.\n") } - appName, err := c.AppName() + appName, err := c.AppNameByFlag() if err != nil { return err } diff --git a/tsuru/client/certificate.go b/tsuru/client/certificate.go index 0892482e..20cb5299 100644 --- a/tsuru/client/certificate.go +++ b/tsuru/client/certificate.go @@ -52,7 +52,7 @@ func (c *CertificateSet) Flags() *gnuflag.FlagSet { } func (c *CertificateSet) Run(context *cmd.Context) error { - appName, err := c.AppName() + appName, err := c.AppNameByFlag() if err != nil { return err } @@ -114,7 +114,7 @@ func (c *CertificateUnset) Flags() *gnuflag.FlagSet { } func (c *CertificateUnset) Run(context *cmd.Context) error { - appName, err := c.AppName() + appName, err := c.AppNameByFlag() if err != nil { return err } @@ -168,7 +168,7 @@ func (c *CertificateList) Flags() *gnuflag.FlagSet { } func (c *CertificateList) Run(context *cmd.Context) error { - appName, err := c.AppName() + appName, err := c.AppNameByFlag() if err != nil { return err } diff --git a/tsuru/client/deploy.go b/tsuru/client/deploy.go index a97c30fd..dbd2cb9e 100644 --- a/tsuru/client/deploy.go +++ b/tsuru/client/deploy.go @@ -55,7 +55,7 @@ type AppDeployList struct { func (c *AppDeployList) Info() *cmd.Info { return &cmd.Info{ Name: "app-deploy-list", - Usage: "app deploy list [-a/--app ]", + Usage: "app deploy list []", Desc: "List information about deploys for an application.", } } @@ -71,7 +71,7 @@ func (c *AppDeployList) Flags() *gnuflag.FlagSet { } func (c *AppDeployList) Run(context *cmd.Context) error { - appName, err := c.AppName() + appName, err := c.AppName(context.Args) if err != nil { return err } @@ -237,7 +237,7 @@ func (c *AppDeploy) Run(context *cmd.Context) error { return errors.New("You can't deploy container image and container file at same time.\n") } - appName, err := c.AppName() + appName, err := c.AppNameByFlag() if err != nil { return err } @@ -408,7 +408,7 @@ func (c *AppDeployRollback) Info() *cmd.Info { } func (c *AppDeployRollback) Run(context *cmd.Context) error { - appName, err := c.AppName() + appName, err := c.AppNameByFlag() if err != nil { return err } @@ -454,16 +454,16 @@ func (c *AppDeployRebuild) Info() *cmd.Info { desc := "Rebuild and deploy the last app image." return &cmd.Info{ Name: "app-deploy-rebuild", - Usage: "app deploy rebuild [-a/--app appname]", + Usage: "app deploy rebuild [appname]", Desc: desc, MinArgs: 0, - MaxArgs: 0, + MaxArgs: 1, } } func (c *AppDeployRebuild) Run(context *cmd.Context) error { context.RawOutput() - appName, err := c.AppName() + appName, err := c.AppName(context.Args) if err != nil { return err } @@ -507,10 +507,10 @@ func (c *AppDeployRollbackUpdate) Info() *cmd.Info { ` return &cmd.Info{ Name: "app-deploy-rollback-update", - Usage: "app deploy rollback update [-a/--app appName] [-i/--image imageName] [-d/--disable] [-r/--reason reason]", + Usage: "app deploy rollback update [appName] [-i/--image imageName] [-d/--disable] [-r/--reason reason]", Desc: desc, MinArgs: 0, - MaxArgs: 0, + MaxArgs: 1, } } @@ -531,7 +531,7 @@ func (c *AppDeployRollbackUpdate) Flags() *gnuflag.FlagSet { } func (c *AppDeployRollbackUpdate) Run(context *cmd.Context) error { - appName, err := c.AppName() + appName, err := c.AppName(context.Args) if err != nil { return err } diff --git a/tsuru/client/log.go b/tsuru/client/log.go index e2d42c2b..5bde4b95 100644 --- a/tsuru/client/log.go +++ b/tsuru/client/log.go @@ -34,7 +34,7 @@ type AppLog struct { func (c *AppLog) Info() *cmd.Info { return &cmd.Info{ Name: "app-log", - Usage: "app log [-a/--app appname] [-l/--lines numberOfLines] [-s/--source source] [-u/--unit unit] [-f/--follow]", + Usage: "app log [appname] [-l/--lines numberOfLines] [-s/--source source] [-u/--unit unit] [-f/--follow]", Desc: `Shows log entries for an application. These logs include everything the application send to stdout and stderr, alongside with logs from tsuru server (deployments, restarts, etc.) @@ -117,7 +117,7 @@ type log struct { func (c *AppLog) Run(context *cmd.Context) error { context.RawOutput() - appName, err := c.AppName() + appName, err := c.AppName(context.Args) if err != nil { return err } diff --git a/tsuru/client/router.go b/tsuru/client/router.go index 7ca24adf..1d6100dd 100644 --- a/tsuru/client/router.go +++ b/tsuru/client/router.go @@ -331,7 +331,7 @@ func (c *AppRoutersList) Flags() *gnuflag.FlagSet { } func (c *AppRoutersList) Run(context *cmd.Context) error { - appName, err := c.AppName() + appName, err := c.AppNameByFlag() if err != nil { return err } @@ -426,7 +426,7 @@ func (c *AppRoutersAdd) Flags() *gnuflag.FlagSet { } func (c *AppRoutersAdd) Run(context *cmd.Context) error { - appName, err := c.AppName() + appName, err := c.AppNameByFlag() if err != nil { return err } @@ -482,7 +482,7 @@ func (c *AppRoutersUpdate) Flags() *gnuflag.FlagSet { } func (c *AppRoutersUpdate) Run(context *cmd.Context) error { - appName, err := c.AppName() + appName, err := c.AppNameByFlag() if err != nil { return err } @@ -527,7 +527,7 @@ func (c *AppRoutersRemove) Info() *cmd.Info { } func (c *AppRoutersRemove) Run(context *cmd.Context) error { - appName, err := c.AppName() + appName, err := c.AppNameByFlag() if err != nil { return err } @@ -553,7 +553,7 @@ type appVersionRouterBase struct { } func (c *appVersionRouterBase) Run(ctx *cmd.Context) error { - appName, err := c.AppName() + appName, err := c.AppNameByFlag() if err != nil { return err } diff --git a/tsuru/client/run.go b/tsuru/client/run.go index 4e48bee1..2f086cd5 100644 --- a/tsuru/client/run.go +++ b/tsuru/client/run.go @@ -43,7 +43,7 @@ Otherwise, it will run the command in all units.` func (c *AppRun) Run(context *cmd.Context) error { context.RawOutput() - appName, err := c.AppName() + appName, err := c.AppNameByFlag() if err != nil { return err } diff --git a/tsuru/client/shell.go b/tsuru/client/shell.go index d9f11d1c..c4e12434 100644 --- a/tsuru/client/shell.go +++ b/tsuru/client/shell.go @@ -58,7 +58,7 @@ type descriptable interface { } func (c *ShellToContainerCmd) Run(context *cmd.Context) error { - appName, err := c.AppName() + appName, err := c.AppNameByFlag() if err != nil { return err } diff --git a/tsuru/client/unit.go b/tsuru/client/unit.go index 63558caa..83a2d297 100644 --- a/tsuru/client/unit.go +++ b/tsuru/client/unit.go @@ -51,7 +51,7 @@ func (c *UnitAdd) Flags() *gnuflag.FlagSet { func (c *UnitAdd) Run(context *cmd.Context) error { context.RawOutput() - appName, err := c.AppName() + appName, err := c.AppNameByFlag() if err != nil { return err } @@ -105,7 +105,7 @@ func (c *UnitRemove) Flags() *gnuflag.FlagSet { func (c *UnitRemove) Run(context *cmd.Context) error { context.RawOutput() - appName, err := c.AppName() + appName, err := c.AppNameByFlag() if err != nil { return err } @@ -219,7 +219,7 @@ func (c *UnitSet) Flags() *gnuflag.FlagSet { func (c *UnitSet) Run(context *cmd.Context) error { context.RawOutput() - appName, err := c.AppName() + appName, err := c.AppNameByFlag() if err != nil { return err } diff --git a/tsuru/client/volume.go b/tsuru/client/volume.go index dcc11ca6..3a636bb8 100644 --- a/tsuru/client/volume.go +++ b/tsuru/client/volume.go @@ -527,7 +527,7 @@ func (c *VolumeBind) Flags() *gnuflag.FlagSet { func (c *VolumeBind) Run(ctx *cmd.Context) error { ctx.RawOutput() volumeName := ctx.Args[0] - appName, err := c.AppName() + appName, err := c.AppNameByFlag() if err != nil { return err } @@ -595,7 +595,7 @@ func (c *VolumeUnbind) Flags() *gnuflag.FlagSet { func (c *VolumeUnbind) Run(ctx *cmd.Context) error { ctx.RawOutput() volumeName := ctx.Args[0] - appName, err := c.AppName() + appName, err := c.AppNameByFlag() if err != nil { return err }