Skip to content

Commit b4c0fa8

Browse files
authored
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.
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()

0 commit comments

Comments
 (0)