Uses the `cliui` output helpers from #30508. `coder tokens create` printed only the new token's secret, so scripts had to call `tokens view` afterwards to get the token's ID, expiry, and scopes. This adds `-o/--output` with `text` (default) and `json`. The JSON document contains the token's metadata from `APIKeyByID` plus the one-time `key`. **Behavior change:** Additive. The default output is still just the secret, so `$(coder tokens create ...)` keeps working. The command now makes one extra API call after creating the token; if it fails, the command prints a warning to stderr and still outputs the secret rather than exiting with an error. <details> <summary>Decisions</summary> - The metadata lookup uses the key ID parsed from the `<id>-<secret>` token, the same convention `tokens view` and `tokens remove` use. - A failed metadata lookup never fails the command, because the token already exists and the secret can't be shown again. </details> Closes [CLI-14](https://linear.app/codercom/issue/CLI-14) _This PR was generated by Coder Agents on behalf of @nickvigilante._
33 lines
884 B
Plaintext
33 lines
884 B
Plaintext
coder v0.0.0-devel
|
|
|
|
USAGE:
|
|
coder tokens create [flags]
|
|
|
|
Create a token
|
|
|
|
OPTIONS:
|
|
--allow allow-list
|
|
Repeatable allow-list entry (`<type>:<uuid>`, e.g.
|
|
workspace:1234-...).
|
|
|
|
--lifetime string, $CODER_TOKEN_LIFETIME
|
|
Duration for the token lifetime. Supports standard Go duration units
|
|
(ns, us, ms, s, m, h) plus d (days) and y (years). Examples: 8h, 30d,
|
|
1y, 1d12h30m.
|
|
|
|
-n, --name string, $CODER_TOKEN_NAME
|
|
Specify a human-readable name.
|
|
|
|
-o, --output text|json (default: text)
|
|
Output format.
|
|
|
|
--scope string-array
|
|
Repeatable scope to attach to the token (e.g. workspace:read).
|
|
|
|
-u, --user string, $CODER_TOKEN_USER
|
|
Specify the user to create the token for (Only works if logged in user
|
|
is admin).
|
|
|
|
———
|
|
Run `coder --help` for a list of global options.
|