Skip to content

Commit 184f062

Browse files
authored
coder licenses add CLI command (#3632)
* coder licenses add CLI command Signed-off-by: Spike Curtis <spike@coder.com> * Fix up lint Signed-off-by: Spike Curtis <spike@coder.com> * Fix t.parallel call Signed-off-by: Spike Curtis <spike@coder.com> * Code review improvements Signed-off-by: Spike Curtis <spike@coder.com> * Lint Signed-off-by: Spike Curtis <spike@coder.com> Signed-off-by: Spike Curtis <spike@coder.com>
1 parent 6dacf70 commit 184f062

32 files changed

+357
-38
lines changed

cli/clitest/clitest.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ import (
2121
// New creates a CLI instance with a configuration pointed to a
2222
// temporary testing directory.
2323
func New(t *testing.T, args ...string) (*cobra.Command, config.Root) {
24-
cmd := cli.Root(cli.AGPL())
24+
return NewWithSubcommands(t, cli.AGPL(), args...)
25+
}
26+
27+
func NewWithSubcommands(
28+
t *testing.T, subcommands []*cobra.Command, args ...string,
29+
) (*cobra.Command, config.Root) {
30+
cmd := cli.Root(subcommands)
2531
dir := t.TempDir()
2632
root := config.Root(dir)
2733
cmd.SetArgs(append([]string{"--global-config", dir}, args...))

cli/configssh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func configSSH() *cobra.Command {
158158
),
159159
Args: cobra.ExactArgs(0),
160160
RunE: func(cmd *cobra.Command, _ []string) error {
161-
client, err := createClient(cmd)
161+
client, err := CreateClient(cmd)
162162
if err != nil {
163163
return err
164164
}

cli/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func create() *cobra.Command {
2727
Use: "create [name]",
2828
Short: "Create a workspace from a template",
2929
RunE: func(cmd *cobra.Command, args []string) error {
30-
client, err := createClient(cmd)
30+
client, err := CreateClient(cmd)
3131
if err != nil {
3232
return err
3333
}

cli/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func deleteWorkspace() *cobra.Command {
2828
return err
2929
}
3030

31-
client, err := createClient(cmd)
31+
client, err := CreateClient(cmd)
3232
if err != nil {
3333
return err
3434
}

cli/features.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func featuresList() *cobra.Command {
3636
Use: "list",
3737
Aliases: []string{"ls"},
3838
RunE: func(cmd *cobra.Command, args []string) error {
39-
client, err := createClient(cmd)
39+
client, err := CreateClient(cmd)
4040
if err != nil {
4141
return err
4242
}

cli/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func list() *cobra.Command {
6565
Aliases: []string{"ls"},
6666
Args: cobra.ExactArgs(0),
6767
RunE: func(cmd *cobra.Command, args []string) error {
68-
client, err := createClient(cmd)
68+
client, err := CreateClient(cmd)
6969
if err != nil {
7070
return err
7171
}

cli/logout.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func logout() *cobra.Command {
1616
Use: "logout",
1717
Short: "Remove the local authenticated session",
1818
RunE: func(cmd *cobra.Command, args []string) error {
19-
client, err := createClient(cmd)
19+
client, err := CreateClient(cmd)
2020
if err != nil {
2121
return err
2222
}

cli/parameterslist.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func parameterList() *cobra.Command {
2222
RunE: func(cmd *cobra.Command, args []string) error {
2323
scope, name := args[0], args[1]
2424

25-
client, err := createClient(cmd)
25+
client, err := CreateClient(cmd)
2626
if err != nil {
2727
return err
2828
}

cli/portforward.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func portForward() *cobra.Command {
7070
return xerrors.New("no port-forwards requested")
7171
}
7272

73-
client, err := createClient(cmd)
73+
client, err := CreateClient(cmd)
7474
if err != nil {
7575
return err
7676
}

cli/publickey.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func publickey() *cobra.Command {
2020
Aliases: []string{"pubkey"},
2121
Short: "Output your public key for Git operations",
2222
RunE: func(cmd *cobra.Command, args []string) error {
23-
client, err := createClient(cmd)
23+
client, err := CreateClient(cmd)
2424
if err != nil {
2525
return xerrors.Errorf("create codersdk client: %w", err)
2626
}

cli/root.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func Root(subcommands []*cobra.Command) *cobra.Command {
114114
return nil
115115
}
116116

117-
client, err := createClient(cmd)
117+
client, err := CreateClient(cmd)
118118
// If the client is unauthenticated we can ignore the check.
119119
// The child commands should handle an unauthenticated client.
120120
if xerrors.Is(err, errUnauthenticated) {
@@ -190,9 +190,9 @@ func isTest() bool {
190190
return flag.Lookup("test.v") != nil
191191
}
192192

193-
// createClient returns a new client from the command context.
193+
// CreateClient returns a new client from the command context.
194194
// It reads from global configuration files if flags are not set.
195-
func createClient(cmd *cobra.Command) (*codersdk.Client, error) {
195+
func CreateClient(cmd *cobra.Command) (*codersdk.Client, error) {
196196
root := createConfig(cmd)
197197
rawURL, err := cmd.Flags().GetString(varURL)
198198
if err != nil || rawURL == "" {
@@ -226,7 +226,7 @@ func createClient(cmd *cobra.Command) (*codersdk.Client, error) {
226226
}
227227

228228
// createAgentClient returns a new client from the command context.
229-
// It works just like createClient, but uses the agent token and URL instead.
229+
// It works just like CreateClient, but uses the agent token and URL instead.
230230
func createAgentClient(cmd *cobra.Command) (*codersdk.Client, error) {
231231
rawURL, err := cmd.Flags().GetString(varAgentURL)
232232
if err != nil {

cli/schedule.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func scheduleShow() *cobra.Command {
7777
Long: scheduleShowDescriptionLong,
7878
Args: cobra.ExactArgs(1),
7979
RunE: func(cmd *cobra.Command, args []string) error {
80-
client, err := createClient(cmd)
80+
client, err := CreateClient(cmd)
8181
if err != nil {
8282
return err
8383
}
@@ -106,7 +106,7 @@ func scheduleStart() *cobra.Command {
106106
Long: scheduleStartDescriptionLong,
107107
Args: cobra.RangeArgs(2, 4),
108108
RunE: func(cmd *cobra.Command, args []string) error {
109-
client, err := createClient(cmd)
109+
client, err := CreateClient(cmd)
110110
if err != nil {
111111
return err
112112
}
@@ -156,7 +156,7 @@ func scheduleStop() *cobra.Command {
156156
Short: "Edit workspace stop schedule",
157157
Long: scheduleStopDescriptionLong,
158158
RunE: func(cmd *cobra.Command, args []string) error {
159-
client, err := createClient(cmd)
159+
client, err := CreateClient(cmd)
160160
if err != nil {
161161
return err
162162
}
@@ -207,7 +207,7 @@ func scheduleOverride() *cobra.Command {
207207
return err
208208
}
209209

210-
client, err := createClient(cmd)
210+
client, err := CreateClient(cmd)
211211
if err != nil {
212212
return xerrors.Errorf("create client: %w", err)
213213
}

cli/show.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func show() *cobra.Command {
1414
Short: "Show details of a workspace's resources and agents",
1515
Args: cobra.ExactArgs(1),
1616
RunE: func(cmd *cobra.Command, args []string) error {
17-
client, err := createClient(cmd)
17+
client, err := CreateClient(cmd)
1818
if err != nil {
1919
return err
2020
}

cli/ssh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func ssh() *cobra.Command {
5454
ctx, cancel := context.WithCancel(cmd.Context())
5555
defer cancel()
5656

57-
client, err := createClient(cmd)
57+
client, err := CreateClient(cmd)
5858
if err != nil {
5959
return err
6060
}

cli/start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func start() *cobra.Command {
1717
Short: "Build a workspace with the start state",
1818
Args: cobra.ExactArgs(1),
1919
RunE: func(cmd *cobra.Command, args []string) error {
20-
client, err := createClient(cmd)
20+
client, err := CreateClient(cmd)
2121
if err != nil {
2222
return err
2323
}

cli/state.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func statePull() *cobra.Command {
2727
Use: "pull <workspace> [file]",
2828
Args: cobra.MinimumNArgs(1),
2929
RunE: func(cmd *cobra.Command, args []string) error {
30-
client, err := createClient(cmd)
30+
client, err := CreateClient(cmd)
3131
if err != nil {
3232
return err
3333
}
@@ -68,7 +68,7 @@ func statePush() *cobra.Command {
6868
Use: "push <workspace> <file>",
6969
Args: cobra.ExactArgs(2),
7070
RunE: func(cmd *cobra.Command, args []string) error {
71-
client, err := createClient(cmd)
71+
client, err := CreateClient(cmd)
7272
if err != nil {
7373
return err
7474
}

cli/stop.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func stop() *cobra.Command {
2525
return err
2626
}
2727

28-
client, err := createClient(cmd)
28+
client, err := CreateClient(cmd)
2929
if err != nil {
3030
return err
3131
}

cli/templatecreate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func templateCreate() *cobra.Command {
3232
Short: "Create a template from the current directory or as specified by flag",
3333
Args: cobra.MaximumNArgs(1),
3434
RunE: func(cmd *cobra.Command, args []string) error {
35-
client, err := createClient(cmd)
35+
client, err := CreateClient(cmd)
3636
if err != nil {
3737
return err
3838
}

cli/templatedelete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func templateDelete() *cobra.Command {
2323
templates = []codersdk.Template{}
2424
)
2525

26-
client, err := createClient(cmd)
26+
client, err := CreateClient(cmd)
2727
if err != nil {
2828
return err
2929
}

cli/templateedit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func templateEdit() *cobra.Command {
2525
Args: cobra.ExactArgs(1),
2626
Short: "Edit the metadata of a template by name.",
2727
RunE: func(cmd *cobra.Command, args []string) error {
28-
client, err := createClient(cmd)
28+
client, err := CreateClient(cmd)
2929
if err != nil {
3030
return xerrors.Errorf("create client: %w", err)
3131
}

cli/templatelist.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func templateList() *cobra.Command {
1616
Short: "List all the templates available for the organization",
1717
Aliases: []string{"ls"},
1818
RunE: func(cmd *cobra.Command, args []string) error {
19-
client, err := createClient(cmd)
19+
client, err := CreateClient(cmd)
2020
if err != nil {
2121
return err
2222
}

cli/templatepull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func templatePull() *cobra.Command {
2929
dest = args[1]
3030
}
3131

32-
client, err := createClient(cmd)
32+
client, err := CreateClient(cmd)
3333
if err != nil {
3434
return xerrors.Errorf("create client: %w", err)
3535
}

cli/templatepush.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func templatePush() *cobra.Command {
2929
Args: cobra.MaximumNArgs(1),
3030
Short: "Push a new template version from the current directory or as specified by flag",
3131
RunE: func(cmd *cobra.Command, args []string) error {
32-
client, err := createClient(cmd)
32+
client, err := CreateClient(cmd)
3333
if err != nil {
3434
return err
3535
}

cli/templateversions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func templateVersionsList() *cobra.Command {
3838
Args: cobra.ExactArgs(1),
3939
Short: "List all the versions of the specified template",
4040
RunE: func(cmd *cobra.Command, args []string) error {
41-
client, err := createClient(cmd)
41+
client, err := CreateClient(cmd)
4242
if err != nil {
4343
return xerrors.Errorf("create client: %w", err)
4444
}

cli/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func update() *cobra.Command {
2222
Args: cobra.ExactArgs(1),
2323
Short: "Update a workspace to the latest template version",
2424
RunE: func(cmd *cobra.Command, args []string) error {
25-
client, err := createClient(cmd)
25+
client, err := CreateClient(cmd)
2626
if err != nil {
2727
return err
2828
}

cli/usercreate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func userCreate() *cobra.Command {
2121
cmd := &cobra.Command{
2222
Use: "create",
2323
RunE: func(cmd *cobra.Command, args []string) error {
24-
client, err := createClient(cmd)
24+
client, err := CreateClient(cmd)
2525
if err != nil {
2626
return err
2727
}

cli/userlist.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func userList() *cobra.Command {
2626
Use: "list",
2727
Aliases: []string{"ls"},
2828
RunE: func(cmd *cobra.Command, args []string) error {
29-
client, err := createClient(cmd)
29+
client, err := CreateClient(cmd)
3030
if err != nil {
3131
return err
3232
}
@@ -76,7 +76,7 @@ func userSingle() *cobra.Command {
7676
),
7777
Args: cobra.ExactArgs(1),
7878
RunE: func(cmd *cobra.Command, args []string) error {
79-
client, err := createClient(cmd)
79+
client, err := CreateClient(cmd)
8080
if err != nil {
8181
return err
8282
}

cli/userstatus.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func createUserStatusCommand(sdkStatus codersdk.UserStatus) *cobra.Command {
4343
},
4444
),
4545
RunE: func(cmd *cobra.Command, args []string) error {
46-
client, err := createClient(cmd)
46+
client, err := CreateClient(cmd)
4747
if err != nil {
4848
return err
4949
}

cli/wireguardtunnel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func wireguardPortForward() *cobra.Command {
6767
return xerrors.New("no port-forwards requested")
6868
}
6969

70-
client, err := createClient(cmd)
70+
client, err := CreateClient(cmd)
7171
if err != nil {
7272
return err
7373
}

0 commit comments

Comments
 (0)