Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Cobra and Organize Help Command Output #1387

Merged
merged 4 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions commands/1_clicks.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ import (
func OneClicks() *Command {
cmd := &Command{
Command: &cobra.Command{
Use: "1-click",
Short: "Display commands that pertain to 1-click applications",
Long: "The commands under `doctl 1-click` are for interacting with DigitalOcean 1-Click applications.",
Use: "1-click",
Short: "Display commands that pertain to 1-click applications",
Long: "The commands under `doctl 1-click` are for interacting with DigitalOcean 1-Click applications.",
GroupID: manageResourcesGroup,
},
}

Expand Down
1 change: 1 addition & 0 deletions commands/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func Account() *Command {
Long: `The subcommands of ` + "`" + `doctl account` + "`" + ` retrieve information about DigitalOcean accounts.

For example, ` + "`" + `doctl account get` + "`" + ` retrieves account profile details, and ` + "`" + `doctl account ratelimit` + "`" + ` retrieves API usage details.`,
GroupID: manageResourcesGroup,
},
}

Expand Down
1 change: 1 addition & 0 deletions commands/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func Apps() *Command {
Aliases: []string{"app", "a"},
Short: "Display commands for working with apps",
Long: "The subcommands of `doctl app` manage your App Platform apps. For documentation on app specs used by multiple commands, see https://www.digitalocean.com/docs/app-platform/concepts/app-spec.",
GroupID: manageResourcesGroup,
},
}

Expand Down
1 change: 1 addition & 0 deletions commands/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ If you work with a just one account, you can call ` + "`" + `doctl auth init` +
To switch between multiple DigitalOcean accounts, including team accounts, you can create named contexts by using ` + "`" + `doctl auth init --context <name>` + "`" + `, then providing a token when prompted. This saves the token under the name you provide. To switch between accounts, use ` + "`" + `doctl auth switch --context <name>` + "`" + `.

To remove accounts from the configuration file, you can run ` + "`" + `doctl auth remove --context <name>` + "`" + `. This removes the token under the name you provide.`,
GroupID: configureDoctlGroup,
},
}

Expand Down
7 changes: 4 additions & 3 deletions commands/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import (
func Balance() *Command {
cmd := &Command{
Command: &cobra.Command{
Use: "balance",
Short: "Display commands for retrieving your account balance",
Long: "The subcommands of `doctl balance` retrieve information about your account balance.",
Use: "balance",
Short: "Display commands for retrieving your account balance",
Long: "The subcommands of `doctl balance` retrieve information about your account balance.",
GroupID: viewBillingGroup,
},
}

Expand Down
1 change: 1 addition & 0 deletions commands/billing_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func BillingHistory() *Command {
Short: "Display commands for retrieving your billing history",
Long: "The subcommands of `doctl billing-history` are used to access the billing history for your DigitalOcean account.",
Aliases: []string{"bh"},
GroupID: viewBillingGroup,
},
}
listBillingHistoryDesc := `This command retrieves the following details for each event in your billing history:
Expand Down
2 changes: 2 additions & 0 deletions commands/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
type Command struct {
*cobra.Command

*cobra.Group

fmtCols []string

childCommands []*Command
Expand Down
1 change: 1 addition & 0 deletions commands/databases.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func Databases() *Command {
Aliases: []string{"db", "dbs", "d", "database"},
Short: "Display commands that manage databases",
Long: "The commands under `doctl databases` are for managing your MySQL, Redis, PostgreSQL, and MongoDB database services.",
GroupID: manageResourcesGroup,
},
}

Expand Down
17 changes: 13 additions & 4 deletions commands/doit.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ import (
)

const (
defaultConfigName = "config.yaml" // default name of config file
defaultConfigName = "config.yaml" // default name of config file
manageResourcesGroup = "manageResources"
configureDoctlGroup = "configureDoctl"
viewBillingGroup = "viewBilling"
)

var (
Expand Down Expand Up @@ -149,6 +152,11 @@ func Execute() {

// AddCommands adds sub commands to the base command.
func addCommands() {

DoitCmd.AddGroup(&cobra.Group{ID: manageResourcesGroup, Title: "Manage DigitalOcean Resources:"})
DoitCmd.AddGroup(&cobra.Group{ID: configureDoctlGroup, Title: "Configure doctl:"})
DoitCmd.AddGroup(&cobra.Group{ID: viewBillingGroup, Title: "View Billing:"})

DoitCmd.AddCommand(Account())
DoitCmd.AddCommand(Apps())
DoitCmd.AddCommand(Auth())
Expand All @@ -170,9 +178,10 @@ func addCommands() {
func computeCmd() *Command {
cmd := &Command{
Command: &cobra.Command{
Use: "compute",
Short: "Display commands that manage infrastructure",
Long: `The subcommands under ` + "`" + `doctl compute` + "`" + ` are for managing DigitalOcean resources.`,
Use: "compute",
Short: "Display commands that manage infrastructure",
Long: `The subcommands under ` + "`" + `doctl compute` + "`" + ` are for managing DigitalOcean resources.`,
GroupID: manageResourcesGroup,
},
}

Expand Down
7 changes: 4 additions & 3 deletions commands/invoices.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ import (
func Invoices() *Command {
cmd := &Command{
Command: &cobra.Command{
Use: "invoice",
Short: "Display commands for retrieving invoices for your account",
Long: "The subcommands of `doctl invoice` retrieve details about invoices for your account.",
Use: "invoice",
Short: "Display commands for retrieving invoices for your account",
Long: "The subcommands of `doctl invoice` retrieve details about invoices for your account.",
GroupID: viewBillingGroup,
},
}

Expand Down
1 change: 1 addition & 0 deletions commands/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func Kubernetes() *Command {
Aliases: []string{"kube", "k8s", "k"},
Short: "Displays commands to manage Kubernetes clusters and configurations",
Long: "The commands under `doctl kubernetes` are for managing Kubernetes clusters and viewing configuration options relating to clusters." + workflowDesc + optionsDesc,
GroupID: manageResourcesGroup,
},
}

Expand Down
1 change: 1 addition & 0 deletions commands/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func Monitoring() *Command {

An alert policy can be applied to resource(s) (currently Droplets)
in order to alert on resource consumption.`,
GroupID: manageResourcesGroup,
},
}

Expand Down
7 changes: 4 additions & 3 deletions commands/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ Projects allow you to organize your DigitalOcean resources (like Droplets, Space

cmd := &Command{
Command: &cobra.Command{
Use: "projects",
Short: "Manage projects and assign resources to them",
Long: "The subcommands of `doctl projects` allow you to create, manage, and assign resources to your projects." + projectsDesc,
Use: "projects",
Short: "Manage projects and assign resources to them",
Long: "The subcommands of `doctl projects` allow you to create, manage, and assign resources to your projects." + projectsDesc,
GroupID: manageResourcesGroup,
},
}

Expand Down
1 change: 1 addition & 0 deletions commands/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func Registry() *Command {
Aliases: []string{"reg", "r"},
Short: "Display commands for working with container registries",
Long: "The subcommands of `doctl registry` create, manage, and allow access to your private container registry.",
GroupID: manageResourcesGroup,
},
}

Expand Down
1 change: 1 addition & 0 deletions commands/serverless.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ A one-time install of the serverless software is needed (use ` + "`" + `doctl se
then ` + "`" + `doctl serverless connect` + "`" + ` to connect to a functions namespace associated with your account).
Other ` + "`" + `doctl serverless` + "`" + ` commands are used to develop, test, and deploy.`,
Aliases: []string{"sandbox", "sbx", "sls"},
GroupID: manageResourcesGroup,
},
}

Expand Down
7 changes: 4 additions & 3 deletions commands/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ import (
func Version() *Command {
return &Command{
Command: &cobra.Command{
Use: "version",
Short: "Show the current version",
Long: "The `doctl version` command displays the version of the doctl software.",
Use: "version",
Short: "Show the current version",
Long: "The `doctl version` command displays the version of the doctl software.",
GroupID: configureDoctlGroup,
Run: func(cmd *cobra.Command, args []string) {
if doctl.Build != "" {
doctl.DoitVersion.Build = doctl.Build
Expand Down
1 change: 1 addition & 0 deletions commands/vpcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func VPCs() *Command {
Long: `The commands under ` + "`" + `doctl vpcs` + "`" + ` are for managing your VPCs.

With the vpcs command, you can list, create, or delete VPCs, and manage their configuration details.`,
GroupID: manageResourcesGroup,
},
}

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
github.com/sclevine/spec v1.3.0
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/cobra v1.4.0
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.11.0
github.com/stretchr/testify v1.8.0
golang.org/x/crypto v0.2.0
Expand Down Expand Up @@ -80,7 +80,7 @@ require (
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hokaccha/go-prettyjson v0.0.0-20210113012101-fb4e108d2519 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.15.12 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
Expand Down Expand Up @@ -415,6 +417,8 @@ github.com/spf13/cast v1.4.1 h1:s0hze+J0196ZfEMTs80N7UlFt0BDuQ7Q+JDnHiMWKdA=
github.com/spf13/cast v1.4.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v1.4.0 h1:y+wJpx64xcgO1V+RcnwW0LEHxTKRi2ZDPSBjWnrg88Q=
github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g=
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
Expand Down
Loading