Skip to content

Commit b4c0fa8

Browse files
authored
chore(cli): rename Cmd to Command (coder#12616)
I think Command is cleaner and my original decision to use "Cmd" a mistake. Plus this creates better parity with cobra.
1 parent 2a77580 commit b4c0fa8

Some content is hidden

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

95 files changed

+313
-311
lines changed

cli/agent.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
"github.com/coder/serpent"
3535
)
3636

37-
func (r *RootCmd) workspaceAgent() *serpent.Cmd {
37+
func (r *RootCmd) workspaceAgent() *serpent.Command {
3838
var (
3939
auth string
4040
logDir string
@@ -49,7 +49,7 @@ func (r *RootCmd) workspaceAgent() *serpent.Cmd {
4949
slogJSONPath string
5050
slogStackdriverPath string
5151
)
52-
cmd := &serpent.Cmd{
52+
cmd := &serpent.Command{
5353
Use: "agent",
5454
Short: `Starts the Coder workspace agent.`,
5555
// This command isn't useful to manually execute.

cli/autoupdate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import (
1111
"github.com/coder/serpent"
1212
)
1313

14-
func (r *RootCmd) autoupdate() *serpent.Cmd {
14+
func (r *RootCmd) autoupdate() *serpent.Command {
1515
client := new(codersdk.Client)
16-
cmd := &serpent.Cmd{
16+
cmd := &serpent.Command{
1717
Annotations: workspaceCommand,
1818
Use: "autoupdate <workspace> <always|never>",
1919
Short: "Toggle auto-update policy for a workspace",

cli/clilog/clilog_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestBuilder(t *testing.T) {
2323
t.Run("NoConfiguration", func(t *testing.T) {
2424
t.Parallel()
2525

26-
cmd := &serpent.Cmd{
26+
cmd := &serpent.Command{
2727
Use: "test",
2828
Handler: testHandler(t),
2929
}
@@ -35,7 +35,7 @@ func TestBuilder(t *testing.T) {
3535
t.Parallel()
3636

3737
tempFile := filepath.Join(t.TempDir(), "test.log")
38-
cmd := &serpent.Cmd{
38+
cmd := &serpent.Command{
3939
Use: "test",
4040
Handler: testHandler(t,
4141
clilog.WithHuman(tempFile),
@@ -51,7 +51,7 @@ func TestBuilder(t *testing.T) {
5151
t.Parallel()
5252

5353
tempFile := filepath.Join(t.TempDir(), "test.log")
54-
cmd := &serpent.Cmd{
54+
cmd := &serpent.Command{
5555
Use: "test",
5656
Handler: testHandler(t,
5757
clilog.WithHuman(tempFile),
@@ -68,7 +68,7 @@ func TestBuilder(t *testing.T) {
6868
t.Parallel()
6969

7070
tempFile := filepath.Join(t.TempDir(), "test.log")
71-
cmd := &serpent.Cmd{
71+
cmd := &serpent.Command{
7272
Use: "test",
7373
Handler: testHandler(t, clilog.WithHuman(tempFile)),
7474
}
@@ -81,7 +81,7 @@ func TestBuilder(t *testing.T) {
8181
t.Parallel()
8282

8383
tempFile := filepath.Join(t.TempDir(), "test.log")
84-
cmd := &serpent.Cmd{
84+
cmd := &serpent.Command{
8585
Use: "test",
8686
Handler: testHandler(t, clilog.WithJSON(tempFile), clilog.WithVerbose()),
8787
}
@@ -107,7 +107,7 @@ func TestBuilder(t *testing.T) {
107107

108108
// Use the default deployment values.
109109
dv := coderdtest.DeploymentValues(t)
110-
cmd := &serpent.Cmd{
110+
cmd := &serpent.Command{
111111
Use: "test",
112112
Handler: testHandler(t, clilog.FromDeploymentValues(dv)),
113113
}
@@ -135,7 +135,7 @@ func TestBuilder(t *testing.T) {
135135
Enable: true,
136136
},
137137
}
138-
cmd := &serpent.Cmd{
138+
cmd := &serpent.Command{
139139
Use: "test",
140140
Handler: testHandler(t, clilog.FromDeploymentValues(dv)),
141141
}
@@ -150,7 +150,7 @@ func TestBuilder(t *testing.T) {
150150
t.Parallel()
151151

152152
tempFile := filepath.Join(t.TempDir(), "doesnotexist", "test.log")
153-
cmd := &serpent.Cmd{
153+
cmd := &serpent.Command{
154154
Use: "test",
155155
Handler: func(inv *serpent.Invocation) error {
156156
logger, closeLog, err := clilog.New(

cli/clitest/clitest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (l *logWriter) Write(p []byte) (n int, err error) {
5656
}
5757

5858
func NewWithCommand(
59-
t testing.TB, cmd *serpent.Cmd, args ...string,
59+
t testing.TB, cmd *serpent.Command, args ...string,
6060
) (*serpent.Invocation, config.Root) {
6161
configDir := config.Root(t.TempDir())
6262
// I really would like to fail test on error logs, but realistically, turning on by default

cli/clitest/golden.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func DefaultCases() []CommandHelpCase {
4848

4949
// TestCommandHelp will test the help output of the given commands
5050
// using golden files.
51-
func TestCommandHelp(t *testing.T, getRoot func(t *testing.T) *serpent.Cmd, cases []CommandHelpCase) {
51+
func TestCommandHelp(t *testing.T, getRoot func(t *testing.T) *serpent.Command, cases []CommandHelpCase) {
5252
t.Parallel()
5353
rootClient, replacements := prepareTestData(t)
5454

@@ -148,7 +148,7 @@ func NormalizeGoldenFile(t *testing.T, byt []byte) []byte {
148148
return byt
149149
}
150150

151-
func extractVisibleCommandPaths(cmdPath []string, cmds []*serpent.Cmd) [][]string {
151+
func extractVisibleCommandPaths(cmdPath []string, cmds []*serpent.Command) [][]string {
152152
var cmdPaths [][]string
153153
for _, c := range cmds {
154154
if c.Hidden {

cli/clitest/handlers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
// non-root commands (like 'groups' or 'users'), a handler is required.
1212
// These handlers are likely just the 'help' handler, but this must be
1313
// explicitly set.
14-
func HandlersOK(t *testing.T, cmd *serpent.Cmd) {
15-
cmd.Walk(func(cmd *serpent.Cmd) {
14+
func HandlersOK(t *testing.T, cmd *serpent.Command) {
15+
cmd.Walk(func(cmd *serpent.Command) {
1616
if cmd.Handler == nil {
1717
// If you see this error, make the Handler a helper invoker.
1818
// Handler: func(inv *serpent.Invocation) error {

cli/cliui/agent_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ func TestAgent(t *testing.T) {
382382
output := make(chan string, 100) // Buffered to avoid blocking, overflow is discarded.
383383
logs := make(chan []codersdk.WorkspaceAgentLog, 1)
384384

385-
cmd := &serpent.Cmd{
385+
cmd := &serpent.Command{
386386
Handler: func(inv *serpent.Invocation) error {
387387
tc.opts.Fetch = func(_ context.Context, _ uuid.UUID) (codersdk.WorkspaceAgent, error) {
388388
t.Log("iter", len(tc.iter))
@@ -450,7 +450,7 @@ func TestAgent(t *testing.T) {
450450
t.Parallel()
451451
var fetchCalled uint64
452452

453-
cmd := &serpent.Cmd{
453+
cmd := &serpent.Command{
454454
Handler: func(inv *serpent.Invocation) error {
455455
buf := bytes.Buffer{}
456456
err := cliui.Agent(inv.Context(), &buf, uuid.Nil, cliui.AgentOptions{

cli/cliui/externalauth_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestExternalAuth(t *testing.T) {
2222
defer cancel()
2323

2424
ptty := ptytest.New(t)
25-
cmd := &serpent.Cmd{
25+
cmd := &serpent.Command{
2626
Handler: func(inv *serpent.Invocation) error {
2727
var fetched atomic.Bool
2828
return cliui.ExternalAuth(inv.Context(), inv.Stdout, cliui.ExternalAuthOptions{

cli/cliui/filter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ var defaultQuery = "owner:me"
1111
// and allows easy integration to a CLI command.
1212
// Example usage:
1313
//
14-
// func (r *RootCmd) MyCmd() *serpent.Cmd {
14+
// func (r *RootCmd) MyCmd() *serpent.Command {
1515
// var (
1616
// filter cliui.WorkspaceFilter
1717
// ...
1818
// )
19-
// cmd := &serpent.Cmd{
19+
// cmd := &serpent.Command{
2020
// ...
2121
// }
2222
// filter.AttachOptions(&cmd.Options)

cli/cliui/output_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func Test_OutputFormatter(t *testing.T) {
101101
},
102102
)
103103

104-
cmd := &serpent.Cmd{}
104+
cmd := &serpent.Command{}
105105
f.AttachOptions(&cmd.Options)
106106

107107
fs := cmd.Options.FlagSet()

cli/cliui/prompt_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func TestPrompt(t *testing.T) {
147147

148148
func newPrompt(ptty *ptytest.PTY, opts cliui.PromptOptions, invOpt func(inv *serpent.Invocation)) (string, error) {
149149
value := ""
150-
cmd := &serpent.Cmd{
150+
cmd := &serpent.Command{
151151
Handler: func(inv *serpent.Invocation) error {
152152
var err error
153153
value, err = cliui.Prompt(inv, opts)
@@ -210,7 +210,7 @@ func TestPasswordTerminalState(t *testing.T) {
210210

211211
// nolint:unused
212212
func passwordHelper() {
213-
cmd := &serpent.Cmd{
213+
cmd := &serpent.Command{
214214
Handler: func(inv *serpent.Invocation) error {
215215
cliui.Prompt(inv, cliui.PromptOptions{
216216
Text: "Password:",

cli/cliui/provisionerjob_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func newProvisionerJob(t *testing.T) provisionerJobTest {
127127
}
128128
jobLock := sync.Mutex{}
129129
logs := make(chan codersdk.ProvisionerJobLog, 1)
130-
cmd := &serpent.Cmd{
130+
cmd := &serpent.Command{
131131
Handler: func(inv *serpent.Invocation) error {
132132
return cliui.ProvisionerJob(inv.Context(), inv.Stdout, cliui.ProvisionerJobOptions{
133133
FetchInterval: time.Millisecond,

cli/cliui/select_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestSelect(t *testing.T) {
3131

3232
func newSelect(ptty *ptytest.PTY, opts cliui.SelectOptions) (string, error) {
3333
value := ""
34-
cmd := &serpent.Cmd{
34+
cmd := &serpent.Command{
3535
Handler: func(inv *serpent.Invocation) error {
3636
var err error
3737
value, err = cliui.Select(inv, opts)
@@ -72,7 +72,7 @@ func TestRichSelect(t *testing.T) {
7272

7373
func newRichSelect(ptty *ptytest.PTY, opts cliui.RichSelectOptions) (string, error) {
7474
value := ""
75-
cmd := &serpent.Cmd{
75+
cmd := &serpent.Command{
7676
Handler: func(inv *serpent.Invocation) error {
7777
richOption, err := cliui.RichSelect(inv, opts)
7878
if err == nil {
@@ -105,7 +105,7 @@ func TestMultiSelect(t *testing.T) {
105105

106106
func newMultiSelect(ptty *ptytest.PTY, items []string) ([]string, error) {
107107
var values []string
108-
cmd := &serpent.Cmd{
108+
cmd := &serpent.Command{
109109
Handler: func(inv *serpent.Invocation) error {
110110
selectedItems, err := cliui.MultiSelect(inv, items)
111111
if err == nil {

cli/configssh.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func sshPrepareWorkspaceConfigs(ctx context.Context, client *codersdk.Client) (r
215215
}
216216
}
217217

218-
func (r *RootCmd) configSSH() *serpent.Cmd {
218+
func (r *RootCmd) configSSH() *serpent.Command {
219219
var (
220220
sshConfigFile string
221221
sshConfigOpts sshConfigOptions
@@ -226,7 +226,7 @@ func (r *RootCmd) configSSH() *serpent.Cmd {
226226
coderCliPath string
227227
)
228228
client := new(codersdk.Client)
229-
cmd := &serpent.Cmd{
229+
cmd := &serpent.Command{
230230
Annotations: workspaceCommand,
231231
Use: "config-ssh",
232232
Short: "Add an SSH Host entry for your workspaces \"ssh coder.workspace\"",

cli/create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"github.com/coder/serpent"
2020
)
2121

22-
func (r *RootCmd) create() *serpent.Cmd {
22+
func (r *RootCmd) create() *serpent.Command {
2323
var (
2424
templateName string
2525
startAt string
@@ -31,7 +31,7 @@ func (r *RootCmd) create() *serpent.Cmd {
3131
copyParametersFrom string
3232
)
3333
client := new(codersdk.Client)
34-
cmd := &serpent.Cmd{
34+
cmd := &serpent.Command{
3535
Annotations: workspaceCommand,
3636
Use: "create [name]",
3737
Short: "Create a workspace",

cli/delete.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import (
1010
)
1111

1212
// nolint
13-
func (r *RootCmd) deleteWorkspace() *serpent.Cmd {
13+
func (r *RootCmd) deleteWorkspace() *serpent.Command {
1414
var orphan bool
1515
client := new(codersdk.Client)
16-
cmd := &serpent.Cmd{
16+
cmd := &serpent.Command{
1717
Annotations: workspaceCommand,
1818
Use: "delete <workspace>",
1919
Short: "Delete a workspace",

cli/dotfiles.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ import (
1919
"github.com/coder/serpent"
2020
)
2121

22-
func (r *RootCmd) dotfiles() *serpent.Cmd {
22+
func (r *RootCmd) dotfiles() *serpent.Command {
2323
var symlinkDir string
2424
var gitbranch string
2525
var dotfilesRepoDir string
2626

27-
cmd := &serpent.Cmd{
27+
cmd := &serpent.Command{
2828
Use: "dotfiles <git_repo_url>",
2929
Middleware: serpent.RequireNArgs(1),
3030
Short: "Personalize your workspace by applying a canonical dotfiles repository",

cli/errors.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import (
1313
"github.com/coder/serpent"
1414
)
1515

16-
func (RootCmd) errorExample() *serpent.Cmd {
17-
errorCmd := func(use string, err error) *serpent.Cmd {
18-
return &serpent.Cmd{
16+
func (RootCmd) errorExample() *serpent.Command {
17+
errorCmd := func(use string, err error) *serpent.Command {
18+
return &serpent.Command{
1919
Use: use,
2020
Handler: func(inv *serpent.Invocation) error {
2121
return err
@@ -52,7 +52,7 @@ func (RootCmd) errorExample() *serpent.Cmd {
5252
// Some flags
5353
var magicWord serpent.String
5454

55-
cmd := &serpent.Cmd{
55+
cmd := &serpent.Command{
5656
Use: "example-error",
5757
Short: "Shows what different error messages look like",
5858
Long: "This command is pretty pointless, but without it testing errors is" +
@@ -61,7 +61,7 @@ func (RootCmd) errorExample() *serpent.Cmd {
6161
Handler: func(inv *serpent.Invocation) error {
6262
return inv.Command.HelpHandler(inv)
6363
},
64-
Children: []*serpent.Cmd{
64+
Children: []*serpent.Command{
6565
// Typical codersdk api error
6666
errorCmd("api", apiError),
6767

cli/exp.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ package cli
22

33
import "github.com/coder/serpent"
44

5-
func (r *RootCmd) expCmd() *serpent.Cmd {
6-
cmd := &serpent.Cmd{
5+
func (r *RootCmd) expCmd() *serpent.Command {
6+
cmd := &serpent.Command{
77
Use: "exp",
88
Short: "Internal commands for testing and experimentation. These are prone to breaking changes with no notice.",
99
Handler: func(i *serpent.Invocation) error {
1010
return i.Command.HelpHandler(i)
1111
},
1212
Hidden: true,
13-
Children: []*serpent.Cmd{
13+
Children: []*serpent.Command{
1414
r.scaletestCmd(),
1515
r.errorExample(),
1616
},

0 commit comments

Comments
 (0)