Skip to content

Commit 9fb98c5

Browse files
committed
add tags to cli
1 parent 35893fb commit 9fb98c5

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

enterprise/cli/provisionerkeys.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ func (r *RootCmd) provisionerKeys() *serpent.Command {
3333
}
3434

3535
func (r *RootCmd) provisionerKeysCreate() *serpent.Command {
36-
orgContext := agpl.NewOrganizationContext()
36+
var (
37+
orgContext = agpl.NewOrganizationContext()
38+
rawTags []string
39+
)
3740

3841
client := new(codersdk.Client)
3942
cmd := &serpent.Command{
@@ -51,8 +54,14 @@ func (r *RootCmd) provisionerKeysCreate() *serpent.Command {
5154
return xerrors.Errorf("current organization: %w", err)
5255
}
5356

57+
tags, err := agpl.ParseProvisionerTags(rawTags)
58+
if err != nil {
59+
return err
60+
}
61+
5462
res, err := client.CreateProvisionerKey(ctx, org.ID, codersdk.CreateProvisionerKeyRequest{
5563
Name: inv.Args[0],
64+
Tags: tags,
5665
})
5766
if err != nil {
5867
return xerrors.Errorf("create provisioner key: %w", err)
@@ -69,7 +78,15 @@ func (r *RootCmd) provisionerKeysCreate() *serpent.Command {
6978
},
7079
}
7180

72-
cmd.Options = serpent.OptionSet{}
81+
cmd.Options = serpent.OptionSet{
82+
{
83+
Flag: "tag",
84+
FlagShorthand: "t",
85+
Env: "CODER_PROVISIONERD_TAGS",
86+
Description: "Tags to filter provisioner jobs by.",
87+
Value: serpent.StringArrayOf(&rawTags),
88+
},
89+
}
7390
orgContext.AttachOptions(cmd)
7491

7592
return cmd

enterprise/cli/provisionerkeys_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestProvisionerKeys(t *testing.T) {
4141
ctx := testutil.Context(t, testutil.WaitMedium)
4242
inv, conf := newCLI(
4343
t,
44-
"provisioner", "keys", "create", name,
44+
"provisioner", "keys", "create", name, "--tag", "foo=bar",
4545
)
4646

4747
pty := ptytest.New(t)
@@ -77,8 +77,10 @@ func TestProvisionerKeys(t *testing.T) {
7777
require.Contains(t, line, "NAME")
7878
require.Contains(t, line, "CREATED AT")
7979
require.Contains(t, line, "ORGANIZATION ID")
80+
require.Contains(t, line, "TAGS")
8081
line = pty.ReadLine(ctx)
8182
require.Contains(t, line, strings.ToLower(name))
83+
require.Contains(t, line, "map[foo:bar]")
8284

8385
inv, conf = newCLI(
8486
t,

0 commit comments

Comments
 (0)