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._
70 lines
1.7 KiB
Markdown
Generated
70 lines
1.7 KiB
Markdown
Generated
---
|
|
# Code generated by make gen. DO NOT EDIT.
|
|
title: "`coder tokens create`"
|
|
description: Create a token.
|
|
---
|
|
|
|
<!-- DO NOT EDIT | GENERATED CONTENT -->
|
|
|
|
Create a token
|
|
|
|
## Usage
|
|
|
|
```console
|
|
coder tokens create [flags]
|
|
```
|
|
|
|
## Options
|
|
|
|
### --lifetime
|
|
|
|
| Property | Value |
|
|
|-------------|------------------------------------|
|
|
| Type | <code>string</code> |
|
|
| Environment | <code>$CODER_TOKEN_LIFETIME</code> |
|
|
|
|
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
|
|
|
|
| Property | Value |
|
|
|-------------|--------------------------------|
|
|
| Type | <code>string</code> |
|
|
| Environment | <code>$CODER_TOKEN_NAME</code> |
|
|
|
|
Specify a human-readable name.
|
|
|
|
### -u, --user
|
|
|
|
| Property | Value |
|
|
|-------------|--------------------------------|
|
|
| Type | <code>string</code> |
|
|
| Environment | <code>$CODER_TOKEN_USER</code> |
|
|
|
|
Specify the user to create the token for (Only works if logged in user is admin).
|
|
|
|
### --scope
|
|
|
|
| Property | Value |
|
|
|----------|---------------------------|
|
|
| Type | <code>string-array</code> |
|
|
|
|
Repeatable scope to attach to the token (e.g. workspace:read).
|
|
|
|
### --allow
|
|
|
|
| Property | Value |
|
|
|----------|-------------------------|
|
|
| Type | <code>allow-list</code> |
|
|
|
|
Repeatable allow-list entry (`<type>:<uuid>`, e.g. workspace:1234-...).
|
|
|
|
### -o, --output
|
|
|
|
| Property | Value |
|
|
|----------|-------------------------|
|
|
| Type | <code>text\|json</code> |
|
|
| Default | <code>text</code> |
|
|
|
|
Output format.
|