mirror of
https://github.com/coder/coder.git
synced 2026-06-03 13:08:25 +00:00
b975d6d9b3
## Description
This PR introduces a `--preset` flag for the `create` command to allow
users to apply a predefined preset to their workspace build.
## Changes
- The `--preset` flag on the `create` command integrates with the
parameter resolution logic and takes precedence over other sources
(e.g., CLI/env vars, last build, etc.).
- Added internal logic to ensure that preset parameters override
parameters values during resolution.
- Updated tests and added new ones to cover these flows.
## Implementation logic
* If a template has presets and includes a default, the CLI will
automatically use the default when `--preset` is not specified.
* If a template has presets but no default, the CLI will prompt the user
to select one when `--preset` is not specified.
* If a template does not have presets, the CLI will not prompt the user
for a preset.
* If the user specifies a preset using the `--preset` flag, that preset
will be used.
* If the user passes `--preset None`, no preset will be applied.
This logic aligns with the behavior in the UI for consistency.
```
> coder create --help
USAGE:
coder create [flags] [workspace]
Create a workspace
- Create a workspace for another user (if you have permission):
$ coder create <username>/<workspace_name>
OPTIONS:
(...)
--preset string, $CODER_PRESET_NAME
Specify the name of a template version preset. Use 'none' to explicitly indicate that no preset should be used.
(...)
-y, --yes bool
Bypass prompts.
```
## Breaking change
**Note:** This is a breaking change to the create CLI command. If a
template includes presets and the user does not provide a `--preset`
flag, the CLI will now prompt the user to select one. This behavior may
break non-interactive scripts or automated workflows.
Relates to PR: https://github.com/coder/coder/pull/18910 - please
consider both PRs together as they’re part of the same workflow
Relates to issue: https://github.com/coder/coder/issues/16594
129 lines
3.9 KiB
Markdown
Generated
129 lines
3.9 KiB
Markdown
Generated
<!-- DO NOT EDIT | GENERATED CONTENT -->
|
|
# create
|
|
|
|
Create a workspace
|
|
|
|
## Usage
|
|
|
|
```console
|
|
coder create [flags] [workspace]
|
|
```
|
|
|
|
## Description
|
|
|
|
```console
|
|
- Create a workspace for another user (if you have permission):
|
|
|
|
$ coder create <username>/<workspace_name>
|
|
```
|
|
|
|
## Options
|
|
|
|
### -t, --template
|
|
|
|
| | |
|
|
|-------------|-----------------------------------|
|
|
| Type | <code>string</code> |
|
|
| Environment | <code>$CODER_TEMPLATE_NAME</code> |
|
|
|
|
Specify a template name.
|
|
|
|
### --template-version
|
|
|
|
| | |
|
|
|-------------|--------------------------------------|
|
|
| Type | <code>string</code> |
|
|
| Environment | <code>$CODER_TEMPLATE_VERSION</code> |
|
|
|
|
Specify a template version name.
|
|
|
|
### --preset
|
|
|
|
| | |
|
|
|-------------|---------------------------------|
|
|
| Type | <code>string</code> |
|
|
| Environment | <code>$CODER_PRESET_NAME</code> |
|
|
|
|
Specify the name of a template version preset. Use 'none' to explicitly indicate that no preset should be used.
|
|
|
|
### --start-at
|
|
|
|
| | |
|
|
|-------------|----------------------------------------|
|
|
| Type | <code>string</code> |
|
|
| Environment | <code>$CODER_WORKSPACE_START_AT</code> |
|
|
|
|
Specify the workspace autostart schedule. Check coder schedule start --help for the syntax.
|
|
|
|
### --stop-after
|
|
|
|
| | |
|
|
|-------------|------------------------------------------|
|
|
| Type | <code>duration</code> |
|
|
| Environment | <code>$CODER_WORKSPACE_STOP_AFTER</code> |
|
|
|
|
Specify a duration after which the workspace should shut down (e.g. 8h).
|
|
|
|
### --automatic-updates
|
|
|
|
| | |
|
|
|-------------|-------------------------------------------------|
|
|
| Type | <code>string</code> |
|
|
| Environment | <code>$CODER_WORKSPACE_AUTOMATIC_UPDATES</code> |
|
|
| Default | <code>never</code> |
|
|
|
|
Specify automatic updates setting for the workspace (accepts 'always' or 'never').
|
|
|
|
### --copy-parameters-from
|
|
|
|
| | |
|
|
|-------------|----------------------------------------------------|
|
|
| Type | <code>string</code> |
|
|
| Environment | <code>$CODER_WORKSPACE_COPY_PARAMETERS_FROM</code> |
|
|
|
|
Specify the source workspace name to copy parameters from.
|
|
|
|
### -y, --yes
|
|
|
|
| | |
|
|
|------|-------------------|
|
|
| Type | <code>bool</code> |
|
|
|
|
Bypass prompts.
|
|
|
|
### --parameter
|
|
|
|
| | |
|
|
|-------------|------------------------------------|
|
|
| Type | <code>string-array</code> |
|
|
| Environment | <code>$CODER_RICH_PARAMETER</code> |
|
|
|
|
Rich parameter value in the format "name=value".
|
|
|
|
### --rich-parameter-file
|
|
|
|
| | |
|
|
|-------------|-----------------------------------------|
|
|
| Type | <code>string</code> |
|
|
| Environment | <code>$CODER_RICH_PARAMETER_FILE</code> |
|
|
|
|
Specify a file path with values for rich parameters defined in the template. The file should be in YAML format, containing key-value pairs for the parameters.
|
|
|
|
### --parameter-default
|
|
|
|
| | |
|
|
|-------------|--------------------------------------------|
|
|
| Type | <code>string-array</code> |
|
|
| Environment | <code>$CODER_RICH_PARAMETER_DEFAULT</code> |
|
|
|
|
Rich parameter default values in the format "name=value".
|
|
|
|
### -O, --org
|
|
|
|
| | |
|
|
|-------------|----------------------------------|
|
|
| Type | <code>string</code> |
|
|
| Environment | <code>$CODER_ORGANIZATION</code> |
|
|
|
|
Select which organization (uuid or name) to use.
|