mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-16 10:09:28 +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)
|
cobra.CheckErr(err)
|
||||||
|
|
||||||
// Prompt for deletion
|
// 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)
|
cobra.CheckErr(err)
|
||||||
|
|
||||||
if !delete {
|
if !delete {
|
||||||
|
|
|
@ -44,9 +44,10 @@ func (b *MalojaApiBackend) Options() []models.BackendOption {
|
||||||
Label: i18n.Tr("Access token"),
|
Label: i18n.Tr("Access token"),
|
||||||
Type: models.Secret,
|
Type: models.Secret,
|
||||||
}, {
|
}, {
|
||||||
Name: "nofix",
|
Name: "nofix",
|
||||||
Label: i18n.Tr("Disable auto correction of submitted listens"),
|
Label: i18n.Tr("Disable auto correction of submitted listens"),
|
||||||
Type: models.Bool,
|
Type: models.Bool,
|
||||||
|
Default: "false",
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,15 +60,20 @@ func PromptSecret(opt models.BackendOption) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func PromptBool(opt models.BackendOption) (bool, 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")
|
yes := i18n.Tr("Yes")
|
||||||
no := i18n.Tr("No")
|
no := i18n.Tr("No")
|
||||||
|
selected := 1
|
||||||
|
if defaultValue {
|
||||||
|
selected = 0
|
||||||
|
}
|
||||||
sel := promptui.Select{
|
sel := promptui.Select{
|
||||||
Label: label,
|
Label: label,
|
||||||
Items: []string{yes, no},
|
Items: []string{yes, no},
|
||||||
|
CursorPos: selected,
|
||||||
}
|
}
|
||||||
_, val, err := sel.Run()
|
_, val, err := sel.Run()
|
||||||
return val == yes, err
|
return val == yes, err
|
||||||
|
|
Loading…
Add table
Reference in a new issue