Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 8212be0

Browse files
committed
Migrate to urfave/cli/v2
1 parent d664df2 commit 8212be0

File tree

13 files changed

+65
-64
lines changed

13 files changed

+65
-64
lines changed

ci/integration/secrets_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func TestSecrets(t *testing.T) {
3939
)
4040

4141
// this tests the "Value:" prompt fallback
42-
c.Run(ctx, fmt.Sprintf("echo %s | coder secrets create %s --from-prompt", value, name)).Assert(t,
42+
c.Run(ctx, fmt.Sprintf("echo %s | coder secrets create --from-prompt %s", value, name)).Assert(t,
4343
tcli.Success(),
4444
tcli.StderrEmpty(),
4545
)
@@ -70,7 +70,7 @@ func TestSecrets(t *testing.T) {
7070

7171
name, value = randString(8), randString(8)
7272

73-
c.Run(ctx, fmt.Sprintf("coder secrets create %s --from-literal %s", name, value)).Assert(t,
73+
c.Run(ctx, fmt.Sprintf("coder secrets create --from-literal %s %s", value, name)).Assert(t,
7474
tcli.Success(),
7575
tcli.StderrEmpty(),
7676
)
@@ -84,10 +84,7 @@ func TestSecrets(t *testing.T) {
8484
c.Run(ctx, fmt.Sprintf("echo %s > ~/secret.json", value)).Assert(t,
8585
tcli.Success(),
8686
)
87-
c.Run(ctx, fmt.Sprintf("coder secrets create %s --from-literal %s --from-file ~/secret.json", name, value)).Assert(t,
88-
tcli.Error(),
89-
)
90-
c.Run(ctx, fmt.Sprintf("coder secrets create %s --from-file ~/secret.json", name)).Assert(t,
87+
c.Run(ctx, fmt.Sprintf("coder secrets create --from-file ~/secret.json %s", name)).Assert(t,
9188
tcli.Success(),
9289
)
9390
//

cmd/coder/configssh.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,30 @@ import (
1313

1414
"cdr.dev/coder-cli/internal/config"
1515
"cdr.dev/coder-cli/internal/entclient"
16-
"github.com/urfave/cli"
16+
"github.com/urfave/cli/v2"
1717
"golang.org/x/xerrors"
1818
)
1919

20-
func makeConfigSSHCmd() cli.Command {
20+
func makeConfigSSHCmd() *cli.Command {
2121
var (
2222
configpath string
2323
remove = false
2424
)
2525

26-
return cli.Command{
26+
return &cli.Command{
2727
Name: "config-ssh",
2828
Usage: "Configure SSH to access Coder environments",
2929
Description: "Inject the proper OpenSSH configuration into your local SSH config file.",
3030
Action: configSSH(&configpath, &remove),
3131
Flags: []cli.Flag{
32-
cli.StringFlag{
32+
&cli.StringFlag{
3333
Name: "filepath",
3434
Usage: "overide the default path of your ssh config file",
3535
Value: filepath.Join(os.Getenv("HOME"), ".ssh", "config"),
3636
TakesFile: true,
3737
Destination: &configpath,
3838
},
39-
cli.BoolFlag{
39+
&cli.BoolFlag{
4040
Name: "remove",
4141
Usage: "remove the auto-generated Coder Enterprise ssh config",
4242
Destination: &remove,

cmd/coder/envs.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ import (
55
"os"
66

77
"cdr.dev/coder-cli/internal/x/xtabwriter"
8-
"github.com/urfave/cli"
8+
"github.com/urfave/cli/v2"
99
"golang.org/x/xerrors"
1010
)
1111

12-
func makeEnvsCommand() cli.Command {
12+
func makeEnvsCommand() *cli.Command {
1313
var outputFmt string
14-
return cli.Command{
14+
return &cli.Command{
1515
Name: "envs",
1616
Usage: "Interact with Coder environments",
1717
Description: "Perform operations on the Coder environments owned by the active user.",
1818
Action: exitHelp,
19-
Subcommands: []cli.Command{
19+
Subcommands: []*cli.Command{
2020
{
2121
Name: "ls",
2222
Usage: "list all environments owned by the active user",
@@ -48,8 +48,9 @@ func makeEnvsCommand() cli.Command {
4848
return nil
4949
},
5050
Flags: []cli.Flag{
51-
cli.StringFlag{
51+
&cli.StringFlag{
5252
Name: "output",
53+
Aliases: []string{"o"},
5354
Usage: "json | human",
5455
Value: "human",
5556
Destination: &outputFmt,

cmd/coder/login.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import (
1010
"cdr.dev/coder-cli/internal/config"
1111
"cdr.dev/coder-cli/internal/loginsrv"
1212
"github.com/pkg/browser"
13-
"github.com/urfave/cli"
13+
"github.com/urfave/cli/v2"
1414
"golang.org/x/xerrors"
1515

1616
"go.coder.com/flog"
1717
)
1818

19-
func makeLoginCmd() cli.Command {
20-
return cli.Command{
19+
func makeLoginCmd() *cli.Command {
20+
return &cli.Command{
2121
Name: "login",
2222
Usage: "Authenticate this client for future operations",
2323
ArgsUsage: "[Coder Enterprise URL eg. http://my.coder.domain/]",

cmd/coder/logout.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import (
44
"os"
55

66
"cdr.dev/coder-cli/internal/config"
7-
"github.com/urfave/cli"
7+
"github.com/urfave/cli/v2"
88
"golang.org/x/xerrors"
99

1010
"go.coder.com/flog"
1111
)
1212

13-
func makeLogoutCmd() cli.Command {
14-
return cli.Command{
13+
func makeLogoutCmd() *cli.Command {
14+
return &cli.Command{
1515
Name: "logout",
1616
Usage: "Remove local authentication credentials if any exist",
1717
Action: logout,

cmd/coder/main.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"runtime"
1010

1111
"cdr.dev/coder-cli/internal/x/xterminal"
12-
"github.com/urfave/cli"
12+
"github.com/urfave/cli/v2"
1313

1414
"go.coder.com/flog"
1515
)
@@ -35,14 +35,12 @@ func main() {
3535
app.Name = "coder"
3636
app.Usage = "coder provides a CLI for working with an existing Coder Enterprise installation"
3737
app.Version = fmt.Sprintf("%s %s %s/%s", version, runtime.Version(), runtime.GOOS, runtime.GOARCH)
38-
app.Author = "Coder Technologies Inc."
3938
app.CommandNotFound = func(c *cli.Context, s string) {
4039
flog.Fatal("command %q not found", s)
4140
}
42-
app.Email = "support@coder.com"
4341
app.Action = exitHelp
4442

45-
app.Commands = []cli.Command{
43+
app.Commands = []*cli.Command{
4644
makeLoginCmd(),
4745
makeLogoutCmd(),
4846
makeShellCmd(),
@@ -59,6 +57,7 @@ func main() {
5957
}
6058
}
6159

62-
func exitHelp(c *cli.Context) {
60+
func exitHelp(c *cli.Context) error {
6361
cli.ShowCommandHelpAndExit(c, c.Command.FullName(), 1)
62+
return nil
6463
}

cmd/coder/secrets.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ import (
88
"cdr.dev/coder-cli/internal/entclient"
99
"cdr.dev/coder-cli/internal/x/xtabwriter"
1010
"github.com/manifoldco/promptui"
11-
"github.com/urfave/cli"
11+
"github.com/urfave/cli/v2"
1212
"golang.org/x/xerrors"
1313

1414
"go.coder.com/flog"
1515
)
1616

17-
func makeSecretsCmd() cli.Command {
18-
return cli.Command{
17+
func makeSecretsCmd() *cli.Command {
18+
return &cli.Command{
1919
Name: "secrets",
2020
Usage: "Interact with Coder Secrets",
2121
Description: "Interact with secrets objects owned by the active user.",
2222
Action: exitHelp,
23-
Subcommands: []cli.Command{
23+
Subcommands: []*cli.Command{
2424
{
2525
Name: "ls",
2626
Usage: "List all secrets owned by the active user",
@@ -43,15 +43,15 @@ func makeSecretsCmd() cli.Command {
4343
}
4444
}
4545

46-
func makeCreateSecret() cli.Command {
46+
func makeCreateSecret() *cli.Command {
4747
var (
4848
fromFile string
4949
fromLiteral string
5050
fromPrompt bool
5151
description string
5252
)
5353

54-
return cli.Command{
54+
return &cli.Command{
5555
Name: "create",
5656
Usage: "Create a new secret",
5757
Description: "Create a new secret object to store application secrets and access them securely from within your environments.",
@@ -114,23 +114,23 @@ func makeCreateSecret() cli.Command {
114114
return nil
115115
},
116116
Flags: []cli.Flag{
117-
cli.StringFlag{
117+
&cli.StringFlag{
118118
Name: "from-file",
119119
Usage: "a file from which to read the value of the secret",
120120
TakesFile: true,
121121
Destination: &fromFile,
122122
},
123-
cli.StringFlag{
123+
&cli.StringFlag{
124124
Name: "from-literal",
125125
Usage: "the value of the secret",
126126
Destination: &fromLiteral,
127127
},
128-
cli.BoolFlag{
128+
&cli.BoolFlag{
129129
Name: "from-prompt",
130130
Usage: "enter the secret value through a terminal prompt",
131131
Destination: &fromPrompt,
132132
},
133-
cli.StringFlag{
133+
&cli.StringFlag{
134134
Name: "description",
135135
Usage: "a description of the secret",
136136
Destination: &description,
@@ -197,10 +197,10 @@ func removeSecrets(c *cli.Context) error {
197197
for _, n := range names {
198198
err := client.DeleteSecretByName(n)
199199
if err != nil {
200-
flog.Error("Failed to delete secret: %v", err)
200+
flog.Error("failed to delete secret %q: %v", n, err)
201201
errorSeen = true
202202
} else {
203-
flog.Info("Successfully deleted secret %q", n)
203+
flog.Success("successfully deleted secret %q", n)
204204
}
205205
}
206206
if errorSeen {

cmd/coder/shell.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"cdr.dev/coder-cli/internal/activity"
1111
"cdr.dev/coder-cli/internal/x/xterminal"
1212
"cdr.dev/wsep"
13-
"github.com/urfave/cli"
13+
"github.com/urfave/cli/v2"
1414
"golang.org/x/crypto/ssh/terminal"
1515
"golang.org/x/time/rate"
1616
"golang.org/x/xerrors"
@@ -19,14 +19,13 @@ import (
1919
"go.coder.com/flog"
2020
)
2121

22-
func makeShellCmd() cli.Command {
23-
return cli.Command{
22+
func makeShellCmd() *cli.Command {
23+
return &cli.Command{
2424
Name: "sh",
2525
Usage: "Open a shell and execute commands in a Coder environment",
2626
Description: "Execute a remote command on the environment\\nIf no command is specified, the default shell is opened.",
2727
ArgsUsage: "[env_name] [<command [args...]>]",
2828
SkipFlagParsing: true,
29-
SkipArgReorder: true,
3029
Before: func(c *cli.Context) error {
3130
if c.Args().First() == "" {
3231
return xerrors.New("argument [env_name] is required")

cmd/coder/sync.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import (
99
"strings"
1010

1111
"cdr.dev/coder-cli/internal/sync"
12-
"github.com/urfave/cli"
12+
"github.com/urfave/cli/v2"
1313
"golang.org/x/xerrors"
1414

1515
"go.coder.com/flog"
1616
)
1717

18-
func makeSyncCmd() cli.Command {
18+
func makeSyncCmd() *cli.Command {
1919
var init bool
20-
return cli.Command{
20+
return &cli.Command{
2121
Name: "sync",
2222
Usage: "Establish a one way directory sync to a Coder environment",
2323
ArgsUsage: "[local directory] [<env name>:<remote directory>]",
@@ -29,7 +29,7 @@ func makeSyncCmd() cli.Command {
2929
},
3030
Action: makeRunSync(&init),
3131
Flags: []cli.Flag{
32-
cli.BoolFlag{
32+
&cli.BoolFlag{
3333
Name: "init",
3434
Usage: "do initial transfer and exit",
3535
Destination: &init,

cmd/coder/urls.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ import (
1010
"strings"
1111

1212
"cdr.dev/coder-cli/internal/x/xtabwriter"
13-
"github.com/urfave/cli"
13+
"github.com/urfave/cli/v2"
1414
"golang.org/x/xerrors"
1515

1616
"go.coder.com/flog"
1717
)
1818

19-
func makeURLCmd() cli.Command {
19+
func makeURLCmd() *cli.Command {
2020
var outputFmt string
21-
return cli.Command{
21+
return &cli.Command{
2222
Name: "urls",
2323
Usage: "Interact with environment DevURLs",
2424
Action: exitHelp,
25-
Subcommands: []cli.Command{
25+
Subcommands: []*cli.Command{
2626
makeCreateDevURL(),
2727
{
2828
Name: "ls",
@@ -39,8 +39,9 @@ func makeURLCmd() cli.Command {
3939
},
4040
Action: makeListDevURLs(&outputFmt),
4141
Flags: []cli.Flag{
42-
cli.StringFlag{
42+
&cli.StringFlag{
4343
Name: "output",
44+
Aliases: []string{"o"},
4445
Usage: "human | json",
4546
Value: "human",
4647
Destination: &outputFmt,
@@ -137,12 +138,12 @@ func makeListDevURLs(outputFmt *string) func(c *cli.Context) error {
137138
}
138139
}
139140

140-
func makeCreateDevURL() cli.Command {
141+
func makeCreateDevURL() *cli.Command {
141142
var (
142143
access string
143144
urlname string
144145
)
145-
return cli.Command{
146+
return &cli.Command{
146147
Name: "create",
147148
Usage: "Create a new devurl for an environment",
148149
ArgsUsage: "[env_name] [port] [--access <level>] [--name <name>]",
@@ -154,13 +155,13 @@ func makeCreateDevURL() cli.Command {
154155
return nil
155156
},
156157
Flags: []cli.Flag{
157-
cli.StringFlag{
158+
&cli.StringFlag{
158159
Name: "access",
159160
Usage: "Set DevURL access to [private | org | authed | public]",
160161
Value: "private",
161162
Destination: &access,
162163
},
163-
cli.StringFlag{
164+
&cli.StringFlag{
164165
Name: "name",
165166
Usage: "DevURL name",
166167
Required: true,

0 commit comments

Comments
 (0)