Allow default value for boolean select

Default for both service delete conformation and disabling Maloja
autofix is now "no".
This commit is contained in:
Philipp Wolfer 2023-12-09 22:15:40 +01:00
parent 6c1cf2101d
commit 76fd7cfeb4
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
3 changed files with 17 additions and 8 deletions

View file

@ -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 {

View file

@ -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",
}}
}

View file

@ -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