Skip to content

chore(cli): rename Cmd to Command #12616

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

Merged
merged 2 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
chore(cli): rename Cmd to Command
I think Command is cleaner and my original decision to use "Cmd"
a mistake.

Plus this creates better parity with cobra.
  • Loading branch information
ammario committed Mar 15, 2024
commit 39cde0dd1de3feea8096a77c9ec6866dfee7faec
4 changes: 2 additions & 2 deletions cli/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"github.com/coder/serpent"
)

func (r *RootCmd) workspaceAgent() *serpent.Cmd {
func (r *RootCmd) workspaceAgent() *serpent.Command {
var (
auth string
logDir string
Expand All @@ -49,7 +49,7 @@ func (r *RootCmd) workspaceAgent() *serpent.Cmd {
slogJSONPath string
slogStackdriverPath string
)
cmd := &serpent.Cmd{
cmd := &serpent.Command{
Use: "agent",
Short: `Starts the Coder workspace agent.`,
// This command isn't useful to manually execute.
Expand Down
4 changes: 2 additions & 2 deletions cli/autoupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"github.com/coder/serpent"
)

func (r *RootCmd) autoupdate() *serpent.Cmd {
func (r *RootCmd) autoupdate() *serpent.Command {
client := new(codersdk.Client)
cmd := &serpent.Cmd{
cmd := &serpent.Command{
Annotations: workspaceCommand,
Use: "autoupdate <workspace> <always|never>",
Short: "Toggle auto-update policy for a workspace",
Expand Down
16 changes: 8 additions & 8 deletions cli/clilog/clilog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestBuilder(t *testing.T) {
t.Run("NoConfiguration", func(t *testing.T) {
t.Parallel()

cmd := &serpent.Cmd{
cmd := &serpent.Command{
Use: "test",
Handler: testHandler(t),
}
Expand All @@ -35,7 +35,7 @@ func TestBuilder(t *testing.T) {
t.Parallel()

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

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

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

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

// Use the default deployment values.
dv := coderdtest.DeploymentValues(t)
cmd := &serpent.Cmd{
cmd := &serpent.Command{
Use: "test",
Handler: testHandler(t, clilog.FromDeploymentValues(dv)),
}
Expand Down Expand Up @@ -135,7 +135,7 @@ func TestBuilder(t *testing.T) {
Enable: true,
},
}
cmd := &serpent.Cmd{
cmd := &serpent.Command{
Use: "test",
Handler: testHandler(t, clilog.FromDeploymentValues(dv)),
}
Expand All @@ -150,7 +150,7 @@ func TestBuilder(t *testing.T) {
t.Parallel()

tempFile := filepath.Join(t.TempDir(), "doesnotexist", "test.log")
cmd := &serpent.Cmd{
cmd := &serpent.Command{
Use: "test",
Handler: func(inv *serpent.Invocation) error {
logger, closeLog, err := clilog.New(
Expand Down
2 changes: 1 addition & 1 deletion cli/clitest/clitest.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (l *logWriter) Write(p []byte) (n int, err error) {
}

func NewWithCommand(
t testing.TB, cmd *serpent.Cmd, args ...string,
t testing.TB, cmd *serpent.Command, args ...string,
) (*serpent.Invocation, config.Root) {
configDir := config.Root(t.TempDir())
// I really would like to fail test on error logs, but realistically, turning on by default
Expand Down
4 changes: 2 additions & 2 deletions cli/clitest/golden.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func DefaultCases() []CommandHelpCase {

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

Expand Down Expand Up @@ -148,7 +148,7 @@ func NormalizeGoldenFile(t *testing.T, byt []byte) []byte {
return byt
}

func extractVisibleCommandPaths(cmdPath []string, cmds []*serpent.Cmd) [][]string {
func extractVisibleCommandPaths(cmdPath []string, cmds []*serpent.Command) [][]string {
var cmdPaths [][]string
for _, c := range cmds {
if c.Hidden {
Expand Down
4 changes: 2 additions & 2 deletions cli/clitest/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
// non-root commands (like 'groups' or 'users'), a handler is required.
// These handlers are likely just the 'help' handler, but this must be
// explicitly set.
func HandlersOK(t *testing.T, cmd *serpent.Cmd) {
cmd.Walk(func(cmd *serpent.Cmd) {
func HandlersOK(t *testing.T, cmd *serpent.Command) {
cmd.Walk(func(cmd *serpent.Command) {
if cmd.Handler == nil {
// If you see this error, make the Handler a helper invoker.
// Handler: func(inv *serpent.Invocation) error {
Expand Down
4 changes: 2 additions & 2 deletions cli/cliui/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ func TestAgent(t *testing.T) {
output := make(chan string, 100) // Buffered to avoid blocking, overflow is discarded.
logs := make(chan []codersdk.WorkspaceAgentLog, 1)

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

cmd := &serpent.Cmd{
cmd := &serpent.Command{
Handler: func(inv *serpent.Invocation) error {
buf := bytes.Buffer{}
err := cliui.Agent(inv.Context(), &buf, uuid.Nil, cliui.AgentOptions{
Expand Down
2 changes: 1 addition & 1 deletion cli/cliui/externalauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestExternalAuth(t *testing.T) {
defer cancel()

ptty := ptytest.New(t)
cmd := &serpent.Cmd{
cmd := &serpent.Command{
Handler: func(inv *serpent.Invocation) error {
var fetched atomic.Bool
return cliui.ExternalAuth(inv.Context(), inv.Stdout, cliui.ExternalAuthOptions{
Expand Down
4 changes: 2 additions & 2 deletions cli/cliui/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ var defaultQuery = "owner:me"
// and allows easy integration to a CLI command.
// Example usage:
//
// func (r *RootCmd) MyCmd() *serpent.Cmd {
// func (r *RootCmd) MyCmd() *serpent.Command {
// var (
// filter cliui.WorkspaceFilter
// ...
// )
// cmd := &serpent.Cmd{
// cmd := &serpent.Command{
// ...
// }
// filter.AttachOptions(&cmd.Options)
Expand Down
2 changes: 1 addition & 1 deletion cli/cliui/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func Test_OutputFormatter(t *testing.T) {
},
)

cmd := &serpent.Cmd{}
cmd := &serpent.Command{}
f.AttachOptions(&cmd.Options)

fs := cmd.Options.FlagSet()
Expand Down
4 changes: 2 additions & 2 deletions cli/cliui/prompt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func TestPrompt(t *testing.T) {

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

// nolint:unused
func passwordHelper() {
cmd := &serpent.Cmd{
cmd := &serpent.Command{
Handler: func(inv *serpent.Invocation) error {
cliui.Prompt(inv, cliui.PromptOptions{
Text: "Password:",
Expand Down
2 changes: 1 addition & 1 deletion cli/cliui/provisionerjob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func newProvisionerJob(t *testing.T) provisionerJobTest {
}
jobLock := sync.Mutex{}
logs := make(chan codersdk.ProvisionerJobLog, 1)
cmd := &serpent.Cmd{
cmd := &serpent.Command{
Handler: func(inv *serpent.Invocation) error {
return cliui.ProvisionerJob(inv.Context(), inv.Stdout, cliui.ProvisionerJobOptions{
FetchInterval: time.Millisecond,
Expand Down
6 changes: 3 additions & 3 deletions cli/cliui/select_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestSelect(t *testing.T) {

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

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

func newMultiSelect(ptty *ptytest.PTY, items []string) ([]string, error) {
var values []string
cmd := &serpent.Cmd{
cmd := &serpent.Command{
Handler: func(inv *serpent.Invocation) error {
selectedItems, err := cliui.MultiSelect(inv, items)
if err == nil {
Expand Down
4 changes: 2 additions & 2 deletions cli/configssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func sshPrepareWorkspaceConfigs(ctx context.Context, client *codersdk.Client) (r
}
}

func (r *RootCmd) configSSH() *serpent.Cmd {
func (r *RootCmd) configSSH() *serpent.Command {
var (
sshConfigFile string
sshConfigOpts sshConfigOptions
Expand All @@ -226,7 +226,7 @@ func (r *RootCmd) configSSH() *serpent.Cmd {
coderCliPath string
)
client := new(codersdk.Client)
cmd := &serpent.Cmd{
cmd := &serpent.Command{
Annotations: workspaceCommand,
Use: "config-ssh",
Short: "Add an SSH Host entry for your workspaces \"ssh coder.workspace\"",
Expand Down
4 changes: 2 additions & 2 deletions cli/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/coder/serpent"
)

func (r *RootCmd) create() *serpent.Cmd {
func (r *RootCmd) create() *serpent.Command {
var (
templateName string
startAt string
Expand All @@ -31,7 +31,7 @@ func (r *RootCmd) create() *serpent.Cmd {
copyParametersFrom string
)
client := new(codersdk.Client)
cmd := &serpent.Cmd{
cmd := &serpent.Command{
Annotations: workspaceCommand,
Use: "create [name]",
Short: "Create a workspace",
Expand Down
4 changes: 2 additions & 2 deletions cli/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
)

// nolint
func (r *RootCmd) deleteWorkspace() *serpent.Cmd {
func (r *RootCmd) deleteWorkspace() *serpent.Command {
var orphan bool
client := new(codersdk.Client)
cmd := &serpent.Cmd{
cmd := &serpent.Command{
Annotations: workspaceCommand,
Use: "delete <workspace>",
Short: "Delete a workspace",
Expand Down
4 changes: 2 additions & 2 deletions cli/dotfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import (
"github.com/coder/serpent"
)

func (r *RootCmd) dotfiles() *serpent.Cmd {
func (r *RootCmd) dotfiles() *serpent.Command {
var symlinkDir string
var gitbranch string
var dotfilesRepoDir string

cmd := &serpent.Cmd{
cmd := &serpent.Command{
Use: "dotfiles <git_repo_url>",
Middleware: serpent.RequireNArgs(1),
Short: "Personalize your workspace by applying a canonical dotfiles repository",
Expand Down
10 changes: 5 additions & 5 deletions cli/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
"github.com/coder/serpent"
)

func (RootCmd) errorExample() *serpent.Cmd {
errorCmd := func(use string, err error) *serpent.Cmd {
return &serpent.Cmd{
func (RootCmd) errorExample() *serpent.Command {
errorCmd := func(use string, err error) *serpent.Command {
return &serpent.Command{
Use: use,
Handler: func(inv *serpent.Invocation) error {
return err
Expand Down Expand Up @@ -52,7 +52,7 @@ func (RootCmd) errorExample() *serpent.Cmd {
// Some flags
var magicWord serpent.String

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

Expand Down
6 changes: 3 additions & 3 deletions cli/exp.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package cli

import "github.com/coder/serpent"

func (r *RootCmd) expCmd() *serpent.Cmd {
cmd := &serpent.Cmd{
func (r *RootCmd) expCmd() *serpent.Command {
cmd := &serpent.Command{
Use: "exp",
Short: "Internal commands for testing and experimentation. These are prone to breaking changes with no notice.",
Handler: func(i *serpent.Invocation) error {
return i.Command.HelpHandler(i)
},
Hidden: true,
Children: []*serpent.Cmd{
Children: []*serpent.Command{
r.scaletestCmd(),
r.errorExample(),
},
Expand Down
Loading