Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

Commit54c2c42

Browse files
committed
feat: Reveal tokens subcommand
* Mark tokens subcommand as visible* Re-generate Markdown documentation for the commands* Add JSON output for "tokens ls" command, as with "envs ls"* Add integration test cases
1 parentc30c076 commit54c2c42

File tree

8 files changed

+176
-9
lines changed

8 files changed

+176
-9
lines changed

‎ci/integration/integration_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ func TestCoderCLI(t *testing.T) {
6161
tcli.Success(),
6262
)
6363

64+
c.Run(ctx,"coder envs ls -o json").Assert(t,
65+
tcli.Success(),
66+
)
67+
68+
c.Run(ctx,"coder tokens").Assert(t,
69+
tcli.Success(),
70+
)
71+
72+
c.Run(ctx,"coder tokens ls").Assert(t,
73+
tcli.Success(),
74+
)
75+
76+
c.Run(ctx,"coder tokens ls -o json").Assert(t,
77+
tcli.Success(),
78+
)
79+
6480
c.Run(ctx,"coder urls").Assert(t,
6581
tcli.Success(),
6682
)
@@ -80,6 +96,10 @@ func TestCoderCLI(t *testing.T) {
8096
c.Run(ctx,"coder envs ls").Assert(t,
8197
tcli.Error(),
8298
)
99+
100+
c.Run(ctx,"coder tokens ls").Assert(t,
101+
tcli.Error(),
102+
)
83103
})
84104
}
85105

‎docs/coder.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ coder provides a CLI for working with an existing Coder Enterprise installation
1919
*[coder logout](coder_logout.md) - Remove local authentication credentials if any exist
2020
*[coder sh](coder_sh.md) - Open a shell and execute commands in a Coder environment
2121
*[coder sync](coder_sync.md) - Establish a one way directory sync to a Coder environment
22+
*[coder tokens](coder_tokens.md) - manage Coder API tokens for the active user
2223
*[coder urls](coder_urls.md) - Interact with environment DevURLs
2324
*[coder users](coder_users.md) - Interact with Coder user accounts
2425

‎docs/coder_tokens.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
##coder tokens
2+
3+
manage Coder API tokens for the active user
4+
5+
###Synopsis
6+
7+
Create and manage API Tokens for authenticating the CLI.
8+
Statically authenticate using the token value with the`CODER_TOKEN` and`CODER_URL` environment variables.
9+
10+
###Options
11+
12+
```
13+
-h, --help help for tokens
14+
```
15+
16+
###Options inherited from parent commands
17+
18+
```
19+
-v, --verbose show verbose output
20+
```
21+
22+
###SEE ALSO
23+
24+
*[coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation
25+
*[coder tokens create](coder_tokens_create.md) - create generates a new API token and prints it to stdout
26+
*[coder tokens ls](coder_tokens_ls.md) - show the user's active API tokens
27+
*[coder tokens regen](coder_tokens_regen.md) - regenerate an API token by its unique ID and print the new token to stdout
28+
*[coder tokens rm](coder_tokens_rm.md) - remove an API token by its unique ID
29+

‎docs/coder_tokens_create.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
##coder tokens create
2+
3+
create generates a new API token and prints it to stdout
4+
5+
```
6+
coder tokens create [token_name] [flags]
7+
```
8+
9+
###Options
10+
11+
```
12+
-h, --help help for create
13+
```
14+
15+
###Options inherited from parent commands
16+
17+
```
18+
-v, --verbose show verbose output
19+
```
20+
21+
###SEE ALSO
22+
23+
*[coder tokens](coder_tokens.md) - manage Coder API tokens for the active user
24+

‎docs/coder_tokens_ls.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
##coder tokens ls
2+
3+
show the user's active API tokens
4+
5+
```
6+
coder tokens ls [flags]
7+
```
8+
9+
###Options
10+
11+
```
12+
-h, --help help for ls
13+
-o, --output string human | json (default "human")
14+
```
15+
16+
###Options inherited from parent commands
17+
18+
```
19+
-v, --verbose show verbose output
20+
```
21+
22+
###SEE ALSO
23+
24+
*[coder tokens](coder_tokens.md) - manage Coder API tokens for the active user
25+

‎docs/coder_tokens_regen.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
##coder tokens regen
2+
3+
regenerate an API token by its unique ID and print the new token to stdout
4+
5+
```
6+
coder tokens regen [token_id] [flags]
7+
```
8+
9+
###Options
10+
11+
```
12+
-h, --help help for regen
13+
```
14+
15+
###Options inherited from parent commands
16+
17+
```
18+
-v, --verbose show verbose output
19+
```
20+
21+
###SEE ALSO
22+
23+
*[coder tokens](coder_tokens.md) - manage Coder API tokens for the active user
24+

‎docs/coder_tokens_rm.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
##coder tokens rm
2+
3+
remove an API token by its unique ID
4+
5+
```
6+
coder tokens rm [token_id] [flags]
7+
```
8+
9+
###Options
10+
11+
```
12+
-h, --help help for rm
13+
```
14+
15+
###Options inherited from parent commands
16+
17+
```
18+
-v, --verbose show verbose output
19+
```
20+
21+
###SEE ALSO
22+
23+
*[coder tokens](coder_tokens.md) - manage Coder API tokens for the active user
24+

‎internal/cmd/tokens.go

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
package cmd
22

33
import (
4+
"encoding/json"
45
"fmt"
5-
6-
"github.com/spf13/cobra"
6+
"os"
77

88
"cdr.dev/coder-cli/coder-sdk"
99
"cdr.dev/coder-cli/internal/x/xcobra"
1010
"cdr.dev/coder-cli/pkg/tablewriter"
11+
12+
"github.com/spf13/cobra"
13+
"golang.org/x/xerrors"
1114
)
1215

1316
functokensCmd()*cobra.Command {
1417
cmd:=&cobra.Command{
15-
Use:"tokens",
16-
Hidden:true,
17-
Short:"manage Coder API tokens for the active user",
18+
Use:"tokens",
19+
Short:"manage Coder API tokens for the active user",
1820
Long:"Create and manage API Tokens for authenticating the CLI.\n"+
1921
"Statically authenticate using the token value with the "+"`"+"CODER_TOKEN"+"`"+" and "+"`"+"CODER_URL"+"`"+" environment variables.",
2022
}
@@ -28,7 +30,9 @@ func tokensCmd() *cobra.Command {
2830
}
2931

3032
funclsTokensCmd()*cobra.Command {
31-
return&cobra.Command{
33+
varoutputFmtstring
34+
35+
cmd:=&cobra.Command{
3236
Use:"ls",
3337
Short:"show the user's active API tokens",
3438
RunE:func(cmd*cobra.Command,args []string)error {
@@ -43,14 +47,30 @@ func lsTokensCmd() *cobra.Command {
4347
returnerr
4448
}
4549

46-
err=tablewriter.WriteTable(len(tokens),func(iint)interface{} {returntokens[i] })
47-
iferr!=nil {
48-
returnerr
50+
switchoutputFmt {
51+
casehumanOutput:
52+
err:=tablewriter.WriteTable(len(tokens),func(iint)interface{} {
53+
returntokens[i]
54+
})
55+
iferr!=nil {
56+
returnxerrors.Errorf("write table: %w",err)
57+
}
58+
casejsonOutput:
59+
err:=json.NewEncoder(os.Stdout).Encode(tokens)
60+
iferr!=nil {
61+
returnxerrors.Errorf("write tokens as JSON: %w",err)
62+
}
63+
default:
64+
returnxerrors.Errorf("unknown --output value %q",outputFmt)
4965
}
5066

5167
returnnil
5268
},
5369
}
70+
71+
cmd.Flags().StringVarP(&outputFmt,"output","o",humanOutput,"human | json")
72+
73+
returncmd
5474
}
5575

5676
funccreateTokensCmd()*cobra.Command {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp