- Notifications
You must be signed in to change notification settings - Fork947
feat(cli): add CLI support for listing presets#18910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Conversation
Long: FormatExamples( | ||
Example{ | ||
Description: "List presets of a specific template version", | ||
Command: "coder templates versions presets list my-template my-template-version", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Currently, thecoder templates versions presets list
command requires both a template and a template version as positional arguments. However, it might be more user-friendly to only require the template name, andby default use the active template version.
We could also introduce a--template-version
flag for cases where the user wants to explicitly list the presets of a specific template version.
Example usage:
# Lists presets for the active version of the templatecoder templates versions presets list my-template# Lists presets for a specific template versioncoder templates versions presets list my-template --template-version my-template-version
Let me know what you think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
coder templates versions presets list
is too verbose. Since we're requiring the template name / version as args/flags, there's no need to mention them in the command IMHO.coder presets
should suffice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I likecoder presets
. I recall seeing the termpreset
used in unrelated work in the frontend a few months ago. Perhaps just check that we won't have any namespacing conflicts if we shorten the command but otherwise I think its a good idea.
I think template version flag should be optional with the active version as a default.
dannykopping left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Before I review further, I'd like to just address some confusion I have:
I'm not really understanding the point of this command.
Users need to be able to specify a preset when creating a workspace. Presumably this command is to allow a user to find out which presets exist so they can pass a value tocoder create
.
However:coder create
provides an interactive and non-interactive mode. If you supply a--template
argument it'll use that value, otherwise interactively list all templates and prompt the user to select one.
I think presets should have the same experience. In other words, we likely don't need this command at all but rather we can move the logic you've already implemented tocoder create
.
That will be the most consistent UX, I believe.
Let me put it another way: were we aware of the interactive nature ofcoder create
? If so, did we decide to design it this way for a particular reason? I can see how this design might fall out of not knowing about the interactive mode.
Long: FormatExamples( | ||
Example{ | ||
Description: "List presets of a specific template version", | ||
Command: "coder templates versions presets list my-template my-template-version", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
coder templates versions presets list
is too verbose. Since we're requiring the template name / version as args/flags, there's no need to mention them in the command IMHO.coder presets
should suffice.
Exactly! One of the goals of this command is to help users discover which presets are available for a given template version, especially in non-interactive, automated environments. The ability to apply a preset during workspace creation is implemented in#18912.
I agree that presets should follow the same behavior in both interactive and non-interactive modes. While the current implementation doesn't include interactive support for presets, I think it absolutely should. I shared some thoughts on this here:https://github.com/coder/coder/pull/18912/files#r2212832022 including ideas on default selection, backward compatibility with scripting workflows, and introducing a "none" option. That said, I believe this command is still valuable in non-interactive scenarios, where users might need to fetch the name of a preset to use during workspace creation.
Yes, we’re aware of that! And while the interactive flow is great for users running In those cases, users typically rely on:
This new command fits naturally into that pattern. It allows users to look up presets that they can then pass via Right now, the CLI does not provide any information about presets, this command gives users a way to discover and inspect available presets for a given template and version. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Looks great@ssncferreira. Some minor comments. I'll check back once we've finalized the thread Danny opened.
@@ -15,6 +15,7 @@ type Preset struct { | |||
Namestring | |||
Parameters []PresetParameter | |||
Defaultbool | |||
Prebuilds*int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Consider clarifying the naming to communicate whether this is the desired number of prebuilds or the eligible number of prebuilds. I can see from elsewhere that its the desired number, but we've spoken in the past about showing how many prebuilds are eligible in the frontend before. Would be good to leave room for both.
@@ -38,12 +39,21 @@ func (api *API) templateVersionPresets(rw http.ResponseWriter, r *http.Request) | |||
return | |||
} | |||
getPrebuildInstances := func(desiredInstances sql.NullInt32) *int { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
this name implies fetching from somewhere, but it only does a type conversion. perhaps consider a more descriptive name?
} | ||
if len(presets) == 0 { | ||
return xerrors.Errorf("no presets found for template %q and template-version %q", template.Name, version.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Should this be an error? Or just an empty list?
My apologies@ssncferreira! I didn't see the other PR, maybe mention it in the description of this one? |
ssncferreira commentedJul 17, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
No worries@dannykopping 😊 it was a totally fair point, and I really appreciate you taking the time to make sure the UX of the CLI is thoughtfully considered. I've updated the description of both PRs to reference each other for clarity. Let me know if anything else is unclear! |
Uh oh!
There was an error while loading.Please reload this page.
Description
This PR introduces a new
list presets
command to display presets correspondent to a template and template version.Changes
list presets
command queries the available presets associated with a template and version, and outputs them in a readable format.Related PR:#18912 - please consider both PRs together as they’re part of the same workflow
Relates to issue:#16594