feat(cli): add CLI support for listing presets (#18910)

## Description 

This PR introduces a new `list presets` command to display the presets
associated with a given template.
By default, it displays the presets for the template's active version,
unless a `--template-version` flag is provided.

## Changes

* Added a new `list presets` command under `coder templates presets` to
display presets associated with a template.
* By default, the command lists presets from the template’s active
version.
* Users can override the default behavior by providing the
`--template-version` flag to target a specific version.

```
> coder templates versions presets list --help

USAGE:
  coder templates presets list [flags] <template>

  List all presets of the specified template. Defaults to the active template version.

OPTIONS:
  -O, --org string, $CODER_ORGANIZATION
          Select which organization (uuid or name) to use.

  -c, --column [name|parameters|default|desired prebuild instances] (default: name,parameters,default,desired prebuild instances)
          Columns to display in table output.

  -o, --output table|json (default: table)
          Output format.

      --template-version string
          Specify a template version to list presets for. Defaults to the active version.
```

Related PR: https://github.com/coder/coder/pull/18912 - please consider
both PRs together as they’re part of the same workflow
Relates to issue: https://github.com/coder/coder/issues/16594

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added CLI commands to manage and list presets for specific template
versions, supporting tabular and JSON output.
* Introduced a new CLI subcommand group for template version presets,
including detailed help and documentation.
* Added support for displaying and managing the desired number of
prebuild instances for presets in CLI, API, and UI.

* **Documentation**
* Updated and expanded CLI and API documentation to describe new
commands, options, and the desired prebuild instances field in presets.
* Added new help output and reference files for template version presets
commands.

* **Bug Fixes**
* Ensured correct handling and display of the desired prebuild instances
property for presets across CLI, API, and UI.

* **Tests**
* Introduced end-to-end tests for listing template version presets,
covering scenarios with and without presets.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Susana Ferreira
2025-07-24 16:44:36 +01:00
committed by GitHub
parent 070178c454
commit 931b97caab
18 changed files with 584 additions and 22 deletions
+1
View File
@@ -33,6 +33,7 @@ workspaces:
| [<code>list</code>](./templates_list.md) | List all the templates available for the organization |
| [<code>push</code>](./templates_push.md) | Create or update a template from the current directory or as specified by flag |
| [<code>versions</code>](./templates_versions.md) | Manage different versions of the specified template |
| [<code>presets</code>](./templates_presets.md) | Manage presets of the specified template |
| [<code>delete</code>](./templates_delete.md) | Delete templates |
| [<code>pull</code>](./templates_pull.md) | Download the active, latest, or specified version of a template to a path. |
| [<code>archive</code>](./templates_archive.md) | Archive unused or failed template versions from a given template(s) |
+32
View File
@@ -0,0 +1,32 @@
<!-- DO NOT EDIT | GENERATED CONTENT -->
# templates presets
Manage presets of the specified template
Aliases:
* preset
## Usage
```console
coder templates presets
```
## Description
```console
- List presets for the active version of a template:
$ coder templates presets list my-template
- List presets for a specific version of a template:
$ coder templates presets list my-template --template-version my-template-version
```
## Subcommands
| Name | Purpose |
|--------------------------------------------------|--------------------------------------------------------------------------------------|
| [<code>list</code>](./templates_presets_list.md) | List all presets of the specified template. Defaults to the active template version. |
+47
View File
@@ -0,0 +1,47 @@
<!-- DO NOT EDIT | GENERATED CONTENT -->
# templates presets list
List all presets of the specified template. Defaults to the active template version.
## Usage
```console
coder templates presets list [flags] <template>
```
## Options
### --template-version
| | |
|------|---------------------|
| Type | <code>string</code> |
Specify a template version to list presets for. Defaults to the active version.
### -O, --org
| | |
|-------------|----------------------------------|
| Type | <code>string</code> |
| Environment | <code>$CODER_ORGANIZATION</code> |
Select which organization (uuid or name) to use.
### -c, --column
| | |
|---------|----------------------------------------------------------------------|
| Type | <code>[name\|parameters\|default\|desired prebuild instances]</code> |
| Default | <code>name,parameters,default,desired prebuild instances</code> |
Columns to display in table output.
### -o, --output
| | |
|---------|--------------------------|
| Type | <code>table\|json</code> |
| Default | <code>table</code> |
Output format.