mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-15 17:49:29 +02:00
Allow default value for boolean select
Default for both service delete conformation and disabling Maloja autofix is now "no".
This commit is contained in:
parent
6c1cf2101d
commit
76fd7cfeb4
3 changed files with 17 additions and 8 deletions
|
@ -38,7 +38,10 @@ var serviceDeleteCmd = &cobra.Command{
|
|||
cobra.CheckErr(err)
|
||||
|
||||
// Prompt for deletion
|
||||
delete, err := cli.PromptYesNo(i18n.Tr("Delete the service configuration \"%v\"?", service))
|
||||
delete, err := cli.PromptYesNo(
|
||||
i18n.Tr("Delete the service configuration \"%v\"?", service),
|
||||
false,
|
||||
)
|
||||
cobra.CheckErr(err)
|
||||
|
||||
if !delete {
|
||||
|
|
|
@ -44,9 +44,10 @@ func (b *MalojaApiBackend) Options() []models.BackendOption {
|
|||
Label: i18n.Tr("Access token"),
|
||||
Type: models.Secret,
|
||||
}, {
|
||||
Name: "nofix",
|
||||
Label: i18n.Tr("Disable auto correction of submitted listens"),
|
||||
Type: models.Bool,
|
||||
Name: "nofix",
|
||||
Label: i18n.Tr("Disable auto correction of submitted listens"),
|
||||
Type: models.Bool,
|
||||
Default: "false",
|
||||
}}
|
||||
}
|
||||
|
||||
|
|
|
@ -60,15 +60,20 @@ func PromptSecret(opt models.BackendOption) (string, error) {
|
|||
}
|
||||
|
||||
func PromptBool(opt models.BackendOption) (bool, error) {
|
||||
return PromptYesNo(opt.Label)
|
||||
return PromptYesNo(opt.Label, opt.Default == "true")
|
||||
}
|
||||
|
||||
func PromptYesNo(label string) (bool, error) {
|
||||
func PromptYesNo(label string, defaultValue bool) (bool, error) {
|
||||
yes := i18n.Tr("Yes")
|
||||
no := i18n.Tr("No")
|
||||
selected := 1
|
||||
if defaultValue {
|
||||
selected = 0
|
||||
}
|
||||
sel := promptui.Select{
|
||||
Label: label,
|
||||
Items: []string{yes, no},
|
||||
Label: label,
|
||||
Items: []string{yes, no},
|
||||
CursorPos: selected,
|
||||
}
|
||||
_, val, err := sel.Run()
|
||||
return val == yes, err
|
||||
|
|
Loading…
Add table
Reference in a new issue