Skip to content

Commit

Permalink
Merge pull request #17 from eunomie/default_values
Browse files Browse the repository at this point in the history
Default values for prompts
  • Loading branch information
eunomie authored Oct 14, 2024
2 parents 67f4404 + 568daf5 commit 500d495
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ actions:
required: true|false # If required, an empty value will not be accepted.
values: # A list of possible values for the option. If set, a select will be displayed to the user.
- VALUE
default: VALUE # The default value for the option.
# The command to run. It's defined as a Go template and can use the following variables:
# - `.Ref` will be replaced by the reference to the image the user provided.
# - `.IsTTY` indicates if the command is run in a TTY environment.
Expand Down
1 change: 1 addition & 0 deletions docs/index.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ actions:
required: true|false # If required, an empty value will not be accepted.
values: # A list of possible values for the option. If set, a select will be displayed to the user.
- VALUE
default: VALUE # The default value for the option.
# The command to run. It's defined as a Go template and can use the following variables:
# - `.Ref` will be replaced by the reference to the image the user provided.
# - `.IsTTY` indicates if the command is run in a TTY environment.
Expand Down
8 changes: 3 additions & 5 deletions internal/commands/cache/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ func pruneNewCmd(dockerCli command.Cli) *cobra.Command {
cache := runkit.NewLocalCache(dockerCli)

if !force {
err := huh.NewForm(
huh.NewGroup(
huh.NewConfirm().
Title("Are you sure you want to remove all cache entries?").
Value(&force))).Run()
err := huh.NewConfirm().
Title("Are you sure you want to remove all cache entries?").
Value(&force).Run()
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion internal/prompt/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,19 @@ func Ask(action *runkit.Action, opts map[string]string) (map[string]string, erro
huh.NewInput().
Title(cmp.Or(opt.Prompt, cmp.Or(opt.Description, opt.Name))).
Key(opt.Name).
Description(opt.Description).
Placeholder(opt.Default).
Suggestions(sugar.If(opt.Default != "", []string{opt.Default}, nil)).
Validate(checkRequired(opt.Required)))
} else {
fields = append(fields,
huh.NewSelect[string]().
Title(cmp.Or(opt.Prompt, cmp.Or(opt.Description, opt.Name))).
Key(opt.Name).
Description(opt.Description).
Validate(checkRequired(opt.Required)).
Options(pizza.Map(opt.Values, func(str string) huh.Option[string] {
return huh.NewOption(str, str)
return huh.NewOption(str, str).Selected(str == opt.Default)
})...))
}
asked = append(asked, opt.Name)
Expand Down
1 change: 1 addition & 0 deletions runkit/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type (
Prompt string `yaml:"prompt,omitempty" json:"prompt,omitempty"`
Required bool `yaml:"required,omitempty" json:"required,omitempty"`
Values []string `yaml:"values,omitempty" json:"values,omitempty"`
Default string `yaml:"default,omitempty" json:"default,omitempty"`
}

ActionType string
Expand Down

0 comments on commit 500d495

Please sign in to comment.