diff --git a/README.md b/README.md index 735bf42..80056b1 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/docs/index.markdown b/docs/index.markdown index 1cd1013..7eddcc5 100644 --- a/docs/index.markdown +++ b/docs/index.markdown @@ -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. diff --git a/internal/commands/cache/prune.go b/internal/commands/cache/prune.go index cf9704a..212e750 100644 --- a/internal/commands/cache/prune.go +++ b/internal/commands/cache/prune.go @@ -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 } diff --git a/internal/prompt/prompt.go b/internal/prompt/prompt.go index 15bdd15..9664702 100644 --- a/internal/prompt/prompt.go +++ b/internal/prompt/prompt.go @@ -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) diff --git a/runkit/types.go b/runkit/types.go index cba5138..f47b08a 100644 --- a/runkit/types.go +++ b/runkit/types.go @@ -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