Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions cli/cliui/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@ import (
"github.com/coder/serpent"
)

func RichParameter(inv *serpent.Invocation, templateVersionParameter codersdk.TemplateVersionParameter, defaultOverrides map[string]string) (string, error) {
label := templateVersionParameter.Name
if templateVersionParameter.DisplayName != "" {
label = templateVersionParameter.DisplayName
}

func RichParameter(inv *serpent.Invocation, templateVersionParameter codersdk.TemplateVersionParameter, name, defaultValue string) (string, error) {
label := name
if templateVersionParameter.Ephemeral {
label += pretty.Sprint(DefaultStyles.Warn, " (build option)")
}
Expand All @@ -26,11 +22,6 @@ func RichParameter(inv *serpent.Invocation, templateVersionParameter codersdk.Te
_, _ = fmt.Fprintln(inv.Stdout, " "+strings.TrimSpace(strings.Join(strings.Split(templateVersionParameter.DescriptionPlaintext, "\n"), "\n "))+"\n")
}

defaultValue := templateVersionParameter.DefaultValue
if v, ok := defaultOverrides[templateVersionParameter.Name]; ok {
defaultValue = v
}

var err error
var value string
switch {
Expand Down
4 changes: 2 additions & 2 deletions cli/cliui/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ type PromptOptions struct {
const skipPromptFlag = "yes"

// SkipPromptOption adds a "--yes/-y" flag to the cmd that can be used to skip
// prompts.
// confirmation prompts.
func SkipPromptOption() serpent.Option {
return serpent.Option{
Flag: skipPromptFlag,
FlagShorthand: "y",
Description: "Bypass prompts.",
Description: "Bypass confirmation prompts.",
// Discard
Value: serpent.BoolOf(new(bool)),
}
Expand Down
22 changes: 17 additions & 5 deletions cli/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ func (r *RootCmd) Create(opts CreateOptions) *serpent.Command {
stopAfter time.Duration
workspaceName string

parameterFlags workspaceParameterFlags
autoUpdates string
copyParametersFrom string
parameterFlags workspaceParameterFlags
autoUpdates string
copyParametersFrom string
useParameterDefaults bool
// Organization context is only required if more than 1 template
// shares the same name across multiple organizations.
orgContext = NewOrganizationContext()
Expand Down Expand Up @@ -309,7 +310,7 @@ func (r *RootCmd) Create(opts CreateOptions) *serpent.Command {
displayAppliedPreset(inv, preset, presetParameters)
} else {
// Inform the user that no preset was applied
_, _ = fmt.Fprintf(inv.Stdout, "%s", cliui.Bold("No preset applied."))
_, _ = fmt.Fprintf(inv.Stdout, "%s\n", cliui.Bold("No preset applied."))
}

if opts.BeforeCreate != nil {
Expand All @@ -330,6 +331,8 @@ func (r *RootCmd) Create(opts CreateOptions) *serpent.Command {
RichParameterDefaults: cliBuildParameterDefaults,

SourceWorkspaceParameters: sourceWorkspaceParameters,

UseParameterDefaults: useParameterDefaults,
})
if err != nil {
return xerrors.Errorf("prepare build: %w", err)
Expand Down Expand Up @@ -436,6 +439,12 @@ func (r *RootCmd) Create(opts CreateOptions) *serpent.Command {
Description: "Specify the source workspace name to copy parameters from.",
Value: serpent.StringOf(&copyParametersFrom),
},
serpent.Option{
Flag: "use-parameter-defaults",
Env: "CODER_WORKSPACE_USE_PARAMETER_DEFAULTS",
Description: "Automatically accept parameter defaults when no value is provided.",
Value: serpent.BoolOf(&useParameterDefaults),
},
cliui.SkipPromptOption(),
)
cmd.Options = append(cmd.Options, parameterFlags.cliParameters()...)
Expand All @@ -460,6 +469,8 @@ type prepWorkspaceBuildArgs struct {
RichParameters []codersdk.WorkspaceBuildParameter
RichParameterFile string
RichParameterDefaults []codersdk.WorkspaceBuildParameter

UseParameterDefaults bool
}

// resolvePreset returns the preset matching the given presetName (if specified),
Expand Down Expand Up @@ -562,7 +573,8 @@ func prepWorkspaceBuild(inv *serpent.Invocation, client *codersdk.Client, args p
WithPromptRichParameters(args.PromptRichParameters).
WithRichParameters(args.RichParameters).
WithRichParametersFile(parameterFile).
WithRichParametersDefaults(args.RichParameterDefaults)
WithRichParametersDefaults(args.RichParameterDefaults).
WithUseParameterDefaults(args.UseParameterDefaults)
buildParameters, err := resolver.Resolve(inv, args.Action, templateVersionParameters)
if err != nil {
return nil, err
Expand Down
Loading
Loading