Skip to content

Commit 9ba00c2

Browse files
wpjuniorclaudeCopilot
authored
Move to cobra part 3 (#250)
* Improve Some command descriptions * Add alias and shorthands support * Drop unused symbols * Add shell completions for common flags Implement dynamic shell completions for app, team, job, pool, plan, platform, and router flags. This enables tab completion in shells for these frequently used flags, improving CLI usability. Also removes local platform struct in favor of appTypes.Platform. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update license header * Remove redundant MinArgs: 0 declarations MinArgs defaults to 0, so explicitly setting it is unnecessary. This cleanup removes the redundant declarations and fixes formatting. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Add shell completions for app/job commands and update shorthands Implement Complete() method for app commands (AppCreate, AppInfo, AppGrant, AppRevoke, AppStop, AppStart, AppRestart) and job commands (JobInfo, JobDelete, JobTrigger, JobUpdate, JobLog) to provide tab completion suggestions. Also fix ShorthandCommand to properly delegate completion to wrapped commands. Update shorthand registrations: add rollback, remove scale. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Add AutoCompleteCommand interface and gray color for env observations - Add AutoCompleteCommand interface for commands with custom arg completion - Implement ValidArgsFunction integration in ManagerV2 for auto-complete - Add common aliases support for FQDN commands on root - Add gray color support to Colorfy for subtle text styling - Apply gray coloring to env variable observations (private, managed by) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update tsuru/client/apps.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Rename autoscale commands and improve deprecated command UX - Rename unit-autoscale-{set,unset,swap} to autoscale-{set,unset,swap} - Register old names as deprecated aliases - Improve DeprecatedCommand to show colored warnings with humanized command names (e.g., "tsuru app info" instead of "app-info") - Add DEPRECATED notice to help output for deprecated commands - Standardize topic descriptions (capitalization and punctuation) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Add shell completions for service commands Implement AutoCompleteCommand interface for service-related commands to provide shell tab-completion for service names, instance names, and team names. Adds ServiceInstanceCompletionMixIn for reusable completion logic across multiple service instance commands. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Use ExtractProgramName * Add generate-doc command for markdown documentation Add a hidden generate-doc command that uses cobra/doc to generate markdown documentation for all CLI commands. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix tests * Attempt to fix CI test on windows * Refactor Manager.Run to return error for proper exit handling Update both V1 and V2 Manager.Run methods to return error instead of calling os.Exit directly. This enables better error propagation and allows main() to handle exit codes consistently. Also simplifies root command configuration by removing redundant runRootCmd function. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Attempt to fix CI test on windows[2] * Enable V2 by default and fix V1-specific tests Change the version check to default to V2 (require explicit v1 to use V1). Remove RemovedCommand which is no longer needed with V2. Add V2() getter to Manager and disable V2 in V1-specific tests. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Fix grammar * Fix ServiceTemplate * Fix test * Drop deprecated AppDeployRebuild --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 422c2ba commit 9ba00c2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2289
-392
lines changed

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ require (
4040
github.com/cespare/xxhash/v2 v2.3.0 // indirect
4141
github.com/containerd/containerd v1.7.29 // indirect
4242
github.com/containerd/log v0.1.0 // indirect
43+
github.com/cpuguy83/go-md2man/v2 v2.0.6 // indirect
4344
github.com/davecgh/go-spew v1.1.1 // indirect
4445
github.com/docker/cli v23.0.3+incompatible // indirect
4546
github.com/docker/docker v28.0.0+incompatible // indirect
@@ -76,6 +77,7 @@ require (
7677
github.com/prometheus/procfs v0.10.1 // indirect
7778
github.com/robfig/cron/v3 v3.0.1 // indirect
7879
github.com/rogpeppe/go-internal v1.9.0 // indirect
80+
github.com/russross/blackfriday/v2 v2.1.0 // indirect
7981
github.com/sagikazarmark/locafero v0.11.0 // indirect
8082
github.com/sirupsen/logrus v1.9.3 // indirect
8183
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ github.com/containerd/containerd v1.7.29 h1:90fWABQsaN9mJhGkoVnuzEY+o1XDPbg9BTC9
2626
github.com/containerd/containerd v1.7.29/go.mod h1:azUkWcOvHrWvaiUjSQH0fjzuHIwSPg1WL5PshGP4Szs=
2727
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
2828
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
29+
github.com/cpuguy83/go-md2man/v2 v2.0.6 h1:XJtiaUW6dEEqVuZiMTn1ldk455QWwEIsMIJlo5vtkx0=
2930
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
3031
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
3132
github.com/creack/pty v1.1.11 h1:07n33Z8lZxZ2qwegKbObQohDhXDQxiMMz1NOUGYlesw=
@@ -228,6 +229,7 @@ github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
228229
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
229230
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
230231
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
232+
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
231233
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
232234
github.com/sabhiram/go-gitignore v0.0.0-20171017070213-362f9845770f h1:FQZgA673tRGrrXIP/OPMO69g81ow4XsKlN/DLH8pSic=
233235
github.com/sabhiram/go-gitignore v0.0.0-20171017070213-362f9845770f/go.mod h1:b18R55ulyQ/h3RaWyloPyER7fWQVZvimKKhnI5OfrJQ=

tsuru/admin/app.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ type AppRoutesRebuild struct {
2020

2121
func (c *AppRoutesRebuild) Info() *cmd.Info {
2222
return &cmd.Info{
23-
Name: "app-routes-rebuild",
24-
MinArgs: 0,
25-
Usage: "app-routes-rebuild <app-name>",
23+
Name: "app-routes-rebuild",
24+
25+
Usage: "app-routes-rebuild <app-name>",
2626
Desc: `Rebuild routes for an application.
2727
This can be used to recover from some failure in the router that caused
2828
existing routes to be lost.`,

tsuru/admin/event.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ type EventBlockList struct {
2828

2929
func (c *EventBlockList) Info() *cmd.Info {
3030
return &cmd.Info{
31-
Name: "event-block-list",
32-
Usage: "event block list [-a/--active]",
33-
Desc: "Lists all event blocks",
34-
MinArgs: 0,
31+
Name: "event-block-list",
32+
Usage: "event block list [-a/--active]",
33+
Desc: "Lists all event blocks",
3534
}
3635
}
3736

tsuru/admin/platform.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,9 @@ import (
2424
"github.com/tsuru/tsuru-client/tsuru/cmd/standards"
2525
"github.com/tsuru/tsuru-client/tsuru/formatter"
2626
tsuruHTTP "github.com/tsuru/tsuru-client/tsuru/http"
27+
appTypes "github.com/tsuru/tsuru/types/app"
2728
)
2829

29-
type platform struct {
30-
Name string `json:"name"`
31-
Disabled bool `json:"disabled"`
32-
}
33-
3430
type PlatformList struct {
3531
fs *pflag.FlagSet
3632
simplified bool
@@ -46,7 +42,7 @@ func (p *PlatformList) Run(context *cmd.Context) error {
4642
if err != nil {
4743
return err
4844
}
49-
var platforms []platform
45+
var platforms []appTypes.Platform
5046
resp, err := tsuruHTTP.AuthenticatedClient.Do(request)
5147
if err != nil {
5248
return err
@@ -103,10 +99,9 @@ func (c *PlatformList) Flags() *pflag.FlagSet {
10399
}
104100
func (*PlatformList) Info() *cmd.Info {
105101
return &cmd.Info{
106-
Name: "platform-list",
107-
Usage: "platform list",
108-
Desc: "Lists the available platforms. All platforms displayed in this list may be used to create new apps (see app-create).",
109-
MinArgs: 0,
102+
Name: "platform-list",
103+
Usage: "platform list",
104+
Desc: "Lists the available platforms. All platforms displayed in this list may be used to create new apps (see app-create).",
110105
}
111106
}
112107

tsuru/admin/platform_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/tsuru/tsuru-client/tsuru/cmd"
1616
"github.com/tsuru/tsuru-client/tsuru/cmd/cmdtest"
1717
tsuruIo "github.com/tsuru/tsuru/io"
18+
appTypes "github.com/tsuru/tsuru/types/app"
1819
"gopkg.in/check.v1"
1920
)
2021

@@ -558,10 +559,10 @@ func (s *S) TestPlatformInfoRun(c *check.C) {
558559
}
559560
expectedMsg := "Name: teste\nStatus: enabled\nImages:\n - tsuru/teste:v2\n - tsuru/teste:v1\n"
560561
res := struct {
561-
Platform platform
562+
Platform appTypes.Platform
562563
Images []string
563564
}{
564-
Platform: platform{Name: name, Disabled: false},
565+
Platform: appTypes.Platform{Name: name, Disabled: false},
565566
Images: []string{"tsuru/teste:v1", "tsuru/teste:v2"},
566567
}
567568
result, err := json.Marshal(res)

tsuru/admin/quota.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ type AppQuotaView struct {
9999

100100
func (*AppQuotaView) Info() *cmd.Info {
101101
return &cmd.Info{
102-
Name: "app-quota-view",
103-
MinArgs: 0,
104-
Usage: "app-quota-view [appname]",
105-
Desc: "Displays the current usage and limit of the given app.",
102+
Name: "app-quota-view",
103+
104+
Usage: "app-quota-view [appname]",
105+
Desc: "Displays the current usage and limit of the given app.",
106106
}
107107
}
108108

tsuru/admin/services.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,9 @@ func (c *ServiceDocGet) Info() *cmd.Info {
241241
type ServiceTemplate struct{}
242242

243243
func (c *ServiceTemplate) Info() *cmd.Info {
244-
usg := `service template
245-
e.g.: $ tsuru service template template`
246244
return &cmd.Info{
247245
Name: "service-template",
248-
Usage: usg,
246+
Usage: "service template",
249247
Desc: "Generates a manifest template file and places it in current directory",
250248
}
251249
}

tsuru/admin/services_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,9 @@ func (s *S) TestServiceDocGetInfo(c *check.C) {
237237

238238
func (s *S) TestServiceTemplateInfo(c *check.C) {
239239
got := (&ServiceTemplate{}).Info()
240-
usg := `service template
241-
e.g.: $ tsuru service template template`
242240
expected := &cmd.Info{
243241
Name: "service-template",
244-
Usage: usg,
242+
Usage: "service template",
245243
Desc: "Generates a manifest template file and places it in current directory",
246244
}
247245
c.Assert(got, check.DeepEquals, expected)

tsuru/auth/login.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ func (c *Login) Info() *cmd.Info {
4242
4343
All tsuru actions require the user to be authenticated (except [[tsuru login]]
4444
and [[tsuru version]]).`,
45-
MinArgs: 0,
4645

4746
V2: cmd.InfoV2{
4847
OnlyAppendOnRoot: true,

0 commit comments

Comments
 (0)