chore(cli): rename Cmd to Command (#12616)

I think Command is cleaner and my original decision to use "Cmd"
a mistake.

Plus this creates better parity with cobra.
This commit is contained in:
Ammar Bandukwala
2024-03-17 09:45:26 -05:00
committed by GitHub
parent 2a77580ba6
commit b4c0fa80d8
95 changed files with 313 additions and 311 deletions
+5 -5
View File
@@ -15,22 +15,22 @@ import (
"github.com/coder/serpent"
)
func (r *RootCmd) features() *serpent.Cmd {
cmd := &serpent.Cmd{
func (r *RootCmd) features() *serpent.Command {
cmd := &serpent.Command{
Short: "List Enterprise features",
Use: "features",
Aliases: []string{"feature"},
Handler: func(inv *serpent.Invocation) error {
return inv.Command.HelpHandler(inv)
},
Children: []*serpent.Cmd{
Children: []*serpent.Command{
r.featuresList(),
},
}
return cmd
}
func (r *RootCmd) featuresList() *serpent.Cmd {
func (r *RootCmd) featuresList() *serpent.Command {
var (
featureColumns = []string{"Name", "Entitlement", "Enabled", "Limit", "Actual"}
columns []string
@@ -38,7 +38,7 @@ func (r *RootCmd) featuresList() *serpent.Cmd {
)
client := new(codersdk.Client)
cmd := &serpent.Cmd{
cmd := &serpent.Command{
Use: "list",
Aliases: []string{"ls"},
Middleware: serpent.Chain(
+2 -2
View File
@@ -12,14 +12,14 @@ import (
"github.com/coder/serpent"
)
func (r *RootCmd) groupCreate() *serpent.Cmd {
func (r *RootCmd) groupCreate() *serpent.Command {
var (
avatarURL string
displayName string
)
client := new(codersdk.Client)
cmd := &serpent.Cmd{
cmd := &serpent.Command{
Use: "create <name>",
Short: "Create a user group",
Middleware: serpent.Chain(
+2 -2
View File
@@ -12,9 +12,9 @@ import (
"github.com/coder/serpent"
)
func (r *RootCmd) groupDelete() *serpent.Cmd {
func (r *RootCmd) groupDelete() *serpent.Command {
client := new(codersdk.Client)
cmd := &serpent.Cmd{
cmd := &serpent.Command{
Use: "delete <name>",
Short: "Delete a user group",
Middleware: serpent.Chain(
+2 -2
View File
@@ -15,7 +15,7 @@ import (
"github.com/coder/serpent"
)
func (r *RootCmd) groupEdit() *serpent.Cmd {
func (r *RootCmd) groupEdit() *serpent.Command {
var (
avatarURL string
name string
@@ -24,7 +24,7 @@ func (r *RootCmd) groupEdit() *serpent.Cmd {
rmUsers []string
)
client := new(codersdk.Client)
cmd := &serpent.Cmd{
cmd := &serpent.Command{
Use: "edit <name>",
Short: "Edit a user group",
Middleware: serpent.Chain(
+2 -2
View File
@@ -13,14 +13,14 @@ import (
"github.com/coder/serpent"
)
func (r *RootCmd) groupList() *serpent.Cmd {
func (r *RootCmd) groupList() *serpent.Command {
formatter := cliui.NewOutputFormatter(
cliui.TableFormat([]groupTableRow{}, nil),
cliui.JSONFormat(),
)
client := new(codersdk.Client)
cmd := &serpent.Cmd{
cmd := &serpent.Command{
Use: "list",
Short: "List user groups",
Middleware: serpent.Chain(
+3 -3
View File
@@ -2,15 +2,15 @@ package cli
import "github.com/coder/serpent"
func (r *RootCmd) groups() *serpent.Cmd {
cmd := &serpent.Cmd{
func (r *RootCmd) groups() *serpent.Command {
cmd := &serpent.Command{
Use: "groups",
Short: "Manage groups",
Aliases: []string{"group"},
Handler: func(inv *serpent.Invocation) error {
return inv.Command.HelpHandler(inv)
},
Children: []*serpent.Cmd{
Children: []*serpent.Command{
r.groupCreate(),
r.groupList(),
r.groupEdit(),
+9 -9
View File
@@ -20,15 +20,15 @@ import (
var jwtRegexp = regexp.MustCompile(`^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$`)
func (r *RootCmd) licenses() *serpent.Cmd {
cmd := &serpent.Cmd{
func (r *RootCmd) licenses() *serpent.Command {
cmd := &serpent.Command{
Short: "Add, delete, and list licenses",
Use: "licenses",
Aliases: []string{"license"},
Handler: func(inv *serpent.Invocation) error {
return inv.Command.HelpHandler(inv)
},
Children: []*serpent.Cmd{
Children: []*serpent.Command{
r.licenseAdd(),
r.licensesList(),
r.licenseDelete(),
@@ -37,14 +37,14 @@ func (r *RootCmd) licenses() *serpent.Cmd {
return cmd
}
func (r *RootCmd) licenseAdd() *serpent.Cmd {
func (r *RootCmd) licenseAdd() *serpent.Command {
var (
filename string
license string
debug bool
)
client := new(codersdk.Client)
cmd := &serpent.Cmd{
cmd := &serpent.Command{
Use: "add [-f file | -l license]",
Short: "Add license to Coder deployment",
Middleware: serpent.Chain(
@@ -136,7 +136,7 @@ func validJWT(s string) error {
return xerrors.New("Invalid license")
}
func (r *RootCmd) licensesList() *serpent.Cmd {
func (r *RootCmd) licensesList() *serpent.Command {
type tableLicense struct {
ID int32 `table:"id,default_sort"`
UUID uuid.UUID `table:"uuid" format:"uuid"`
@@ -208,7 +208,7 @@ func (r *RootCmd) licensesList() *serpent.Cmd {
)
client := new(codersdk.Client)
cmd := &serpent.Cmd{
cmd := &serpent.Command{
Use: "list",
Short: "List licenses (including expired)",
Aliases: []string{"ls"},
@@ -239,9 +239,9 @@ func (r *RootCmd) licensesList() *serpent.Cmd {
return cmd
}
func (r *RootCmd) licenseDelete() *serpent.Cmd {
func (r *RootCmd) licenseDelete() *serpent.Command {
client := new(codersdk.Client)
cmd := &serpent.Cmd{
cmd := &serpent.Command{
Use: "delete <id>",
Short: "Delete license by ID",
Aliases: []string{"del"},
+5 -5
View File
@@ -32,14 +32,14 @@ import (
"github.com/coder/serpent"
)
func (r *RootCmd) provisionerDaemons() *serpent.Cmd {
cmd := &serpent.Cmd{
func (r *RootCmd) provisionerDaemons() *serpent.Command {
cmd := &serpent.Command{
Use: "provisionerd",
Short: "Manage provisioner daemons",
Handler: func(inv *serpent.Invocation) error {
return inv.Command.HelpHandler(inv)
},
Children: []*serpent.Cmd{
Children: []*serpent.Command{
r.provisionerDaemonStart(),
},
}
@@ -57,7 +57,7 @@ func validateProvisionerDaemonName(name string) error {
return nil
}
func (r *RootCmd) provisionerDaemonStart() *serpent.Cmd {
func (r *RootCmd) provisionerDaemonStart() *serpent.Command {
var (
cacheDir string
logHuman string
@@ -75,7 +75,7 @@ func (r *RootCmd) provisionerDaemonStart() *serpent.Cmd {
prometheusAddress string
)
client := new(codersdk.Client)
cmd := &serpent.Cmd{
cmd := &serpent.Command{
Use: "start",
Short: "Run a provisioner daemon",
Middleware: serpent.Chain(
+2 -2
View File
@@ -7,8 +7,8 @@ import (
"github.com/coder/serpent"
)
func (r *RootCmd) provisionerDaemons() *serpent.Cmd {
cmd := &serpent.Cmd{
func (r *RootCmd) provisionerDaemons() *serpent.Command {
cmd := &serpent.Command{
Use: "provisionerd",
Short: "Manage provisioner daemons",
// We accept RawArgs so all commands and flags are accepted.
+2 -2
View File
@@ -44,7 +44,7 @@ func (c *closers) Add(f func()) {
*c = append(*c, f)
}
func (r *RootCmd) proxyServer() *serpent.Cmd {
func (r *RootCmd) proxyServer() *serpent.Command {
var (
cfg = new(codersdk.DeploymentValues)
// Filter options for only relevant ones.
@@ -102,7 +102,7 @@ func (r *RootCmd) proxyServer() *serpent.Cmd {
},
)
cmd := &serpent.Cmd{
cmd := &serpent.Command{
Use: "server",
Short: "Start a workspace proxy server",
Options: opts,
+2 -2
View File
@@ -7,8 +7,8 @@ import (
"github.com/coder/serpent"
)
func (r *RootCmd) proxyServer() *serpent.Cmd {
root := &serpent.Cmd{
func (r *RootCmd) proxyServer() *serpent.Command {
root := &serpent.Command{
Use: "server",
Short: "Start a workspace proxy server",
Aliases: []string{},
+3 -3
View File
@@ -9,8 +9,8 @@ type RootCmd struct {
cli.RootCmd
}
func (r *RootCmd) enterpriseOnly() []*serpent.Cmd {
return []*serpent.Cmd{
func (r *RootCmd) enterpriseOnly() []*serpent.Command {
return []*serpent.Command{
r.Server(nil),
r.workspaceProxy(),
r.features(),
@@ -20,7 +20,7 @@ func (r *RootCmd) enterpriseOnly() []*serpent.Cmd {
}
}
func (r *RootCmd) EnterpriseSubcommands() []*serpent.Cmd {
func (r *RootCmd) EnterpriseSubcommands() []*serpent.Command {
all := append(r.Core(), r.enterpriseOnly()...)
return all
}
+1 -1
View File
@@ -13,7 +13,7 @@ import (
//nolint:tparallel,paralleltest
func TestEnterpriseCommandHelp(t *testing.T) {
// Only test the enterprise commands
getCmds := func(t *testing.T) *serpent.Cmd {
getCmds := func(t *testing.T) *serpent.Command {
// Must return a fresh instance of cmds each time.
t.Helper()
var root cli.RootCmd
+1 -1
View File
@@ -28,7 +28,7 @@ import (
agplcoderd "github.com/coder/coder/v2/coderd"
)
func (r *RootCmd) Server(_ func()) *serpent.Cmd {
func (r *RootCmd) Server(_ func()) *serpent.Command {
cmd := r.RootCmd.Server(func(ctx context.Context, options *agplcoderd.Options) (*agplcoderd.API, io.Closer, error) {
if options.DeploymentValues.DERP.Server.RelayURL.String() != "" {
_, err := url.Parse(options.DeploymentValues.DERP.Server.RelayURL.String())
+8 -8
View File
@@ -18,8 +18,8 @@ import (
"golang.org/x/xerrors"
)
func (r *RootCmd) dbcryptCmd() *serpent.Cmd {
dbcryptCmd := &serpent.Cmd{
func (r *RootCmd) dbcryptCmd() *serpent.Command {
dbcryptCmd := &serpent.Command{
Use: "dbcrypt",
Short: "Manage database encryption.",
Handler: func(inv *serpent.Invocation) error {
@@ -34,9 +34,9 @@ func (r *RootCmd) dbcryptCmd() *serpent.Cmd {
return dbcryptCmd
}
func (*RootCmd) dbcryptRotateCmd() *serpent.Cmd {
func (*RootCmd) dbcryptRotateCmd() *serpent.Command {
var flags rotateFlags
cmd := &serpent.Cmd{
cmd := &serpent.Command{
Use: "rotate",
Short: "Rotate database encryption keys.",
Handler: func(inv *serpent.Invocation) error {
@@ -107,9 +107,9 @@ func (*RootCmd) dbcryptRotateCmd() *serpent.Cmd {
return cmd
}
func (*RootCmd) dbcryptDecryptCmd() *serpent.Cmd {
func (*RootCmd) dbcryptDecryptCmd() *serpent.Command {
var flags decryptFlags
cmd := &serpent.Cmd{
cmd := &serpent.Command{
Use: "decrypt",
Short: "Decrypt a previously encrypted database.",
Handler: func(inv *serpent.Invocation) error {
@@ -164,9 +164,9 @@ func (*RootCmd) dbcryptDecryptCmd() *serpent.Cmd {
return cmd
}
func (*RootCmd) dbcryptDeleteCmd() *serpent.Cmd {
func (*RootCmd) dbcryptDeleteCmd() *serpent.Command {
var flags deleteFlags
cmd := &serpent.Cmd{
cmd := &serpent.Command{
Use: "delete",
Short: "Delete all encrypted data from the database. THIS IS A DESTRUCTIVE OPERATION.",
Handler: func(inv *serpent.Invocation) error {
+13 -13
View File
@@ -15,8 +15,8 @@ import (
"github.com/coder/serpent"
)
func (r *RootCmd) workspaceProxy() *serpent.Cmd {
cmd := &serpent.Cmd{
func (r *RootCmd) workspaceProxy() *serpent.Command {
cmd := &serpent.Command{
Use: "workspace-proxy",
Short: "Workspace proxies provide low-latency experiences for geo-distributed teams.",
Long: "Workspace proxies provide low-latency experiences for geo-distributed teams. " +
@@ -27,7 +27,7 @@ func (r *RootCmd) workspaceProxy() *serpent.Cmd {
Handler: func(inv *serpent.Invocation) error {
return inv.Command.HelpHandler(inv)
},
Children: []*serpent.Cmd{
Children: []*serpent.Command{
r.proxyServer(),
r.createProxy(),
r.deleteProxy(),
@@ -40,10 +40,10 @@ func (r *RootCmd) workspaceProxy() *serpent.Cmd {
return cmd
}
func (r *RootCmd) regenerateProxyToken() *serpent.Cmd {
func (r *RootCmd) regenerateProxyToken() *serpent.Command {
formatter := newUpdateProxyResponseFormatter()
client := new(codersdk.Client)
cmd := &serpent.Cmd{
cmd := &serpent.Command{
Use: "regenerate-token <name|id>",
Short: "Regenerate a workspace proxy authentication token. " +
"This will invalidate the existing authentication token.",
@@ -86,7 +86,7 @@ func (r *RootCmd) regenerateProxyToken() *serpent.Cmd {
return cmd
}
func (r *RootCmd) patchProxy() *serpent.Cmd {
func (r *RootCmd) patchProxy() *serpent.Command {
var (
proxyName string
displayName string
@@ -113,7 +113,7 @@ func (r *RootCmd) patchProxy() *serpent.Cmd {
)
)
client := new(codersdk.Client)
cmd := &serpent.Cmd{
cmd := &serpent.Command{
Use: "edit <name|id>",
Short: "Edit a workspace proxy",
Middleware: serpent.Chain(
@@ -186,9 +186,9 @@ func (r *RootCmd) patchProxy() *serpent.Cmd {
return cmd
}
func (r *RootCmd) deleteProxy() *serpent.Cmd {
func (r *RootCmd) deleteProxy() *serpent.Command {
client := new(codersdk.Client)
cmd := &serpent.Cmd{
cmd := &serpent.Command{
Use: "delete <name|id>",
Short: "Delete a workspace proxy",
Options: serpent.OptionSet{
@@ -229,7 +229,7 @@ func (r *RootCmd) deleteProxy() *serpent.Cmd {
return cmd
}
func (r *RootCmd) createProxy() *serpent.Cmd {
func (r *RootCmd) createProxy() *serpent.Command {
var (
proxyName string
displayName string
@@ -245,7 +245,7 @@ func (r *RootCmd) createProxy() *serpent.Cmd {
}
client := new(codersdk.Client)
cmd := &serpent.Cmd{
cmd := &serpent.Command{
Use: "create",
Short: "Create a workspace proxy",
Middleware: serpent.Chain(
@@ -335,7 +335,7 @@ func (r *RootCmd) createProxy() *serpent.Cmd {
return cmd
}
func (r *RootCmd) listProxies() *serpent.Cmd {
func (r *RootCmd) listProxies() *serpent.Command {
formatter := cliui.NewOutputFormatter(
cliui.TableFormat([]codersdk.WorkspaceProxy{}, []string{"name", "url", "proxy status"}),
cliui.JSONFormat(),
@@ -363,7 +363,7 @@ func (r *RootCmd) listProxies() *serpent.Cmd {
)
client := new(codersdk.Client)
cmd := &serpent.Cmd{
cmd := &serpent.Command{
Use: "ls",
Aliases: []string{"list"},
Short: "List all workspace proxies",