forked from TrueCloudLab/rclone
config: show default and example values in correct input syntax instead of quoted and escaped golang string syntax
See #5551
This commit is contained in:
parent
a301478a13
commit
b783f09fc6
1 changed files with 31 additions and 22 deletions
|
@ -101,10 +101,12 @@ func Choose(what string, kind string, choices, help []string, defaultValue strin
|
||||||
valueDescription = "your own"
|
valueDescription = "your own"
|
||||||
}
|
}
|
||||||
fmt.Printf("Choose a number from below, or type in %s %s.\n", valueDescription, kind)
|
fmt.Printf("Choose a number from below, or type in %s %s.\n", valueDescription, kind)
|
||||||
if !required || defaultValue != "" {
|
|
||||||
// Empty input is allowed if not required is set, or if
|
// Empty input is allowed if not required is set, or if
|
||||||
// required is set but there is a default value to use.
|
// required is set but there is a default value to use.
|
||||||
fmt.Printf("Press Enter for the default (%q).\n", defaultValue)
|
if defaultValue != "" {
|
||||||
|
fmt.Printf("Press Enter for the default (%s).\n", defaultValue)
|
||||||
|
} else if !required {
|
||||||
|
fmt.Printf("Press Enter to leave empty.\n")
|
||||||
}
|
}
|
||||||
attributes := []string{terminal.HiRedFg, terminal.HiGreenFg}
|
attributes := []string{terminal.HiRedFg, terminal.HiGreenFg}
|
||||||
for i, text := range choices {
|
for i, text := range choices {
|
||||||
|
@ -113,7 +115,7 @@ func Choose(what string, kind string, choices, help []string, defaultValue strin
|
||||||
parts := strings.Split(help[i], "\n")
|
parts := strings.Split(help[i], "\n")
|
||||||
lines = append(lines, parts...)
|
lines = append(lines, parts...)
|
||||||
}
|
}
|
||||||
lines = append(lines, fmt.Sprintf("%q", text))
|
lines = append(lines, fmt.Sprintf("(%s)", text))
|
||||||
pos := i + 1
|
pos := i + 1
|
||||||
terminal.WriteString(attributes[i%len(attributes)])
|
terminal.WriteString(attributes[i%len(attributes)])
|
||||||
if len(lines) == 1 {
|
if len(lines) == 1 {
|
||||||
|
@ -179,12 +181,15 @@ func Choose(what string, kind string, choices, help []string, defaultValue strin
|
||||||
|
|
||||||
// Enter prompts for an input value of a specified type
|
// Enter prompts for an input value of a specified type
|
||||||
func Enter(what string, kind string, defaultValue string, required bool) string {
|
func Enter(what string, kind string, defaultValue string, required bool) string {
|
||||||
if !required || defaultValue != "" {
|
|
||||||
// Empty input is allowed if not required is set, or if
|
// Empty input is allowed if not required is set, or if
|
||||||
// required is set but there is a default value to use.
|
// required is set but there is a default value to use.
|
||||||
fmt.Printf("Enter a %s. Press Enter for the default (%q).\n", kind, defaultValue)
|
fmt.Printf("Enter a %s.", kind)
|
||||||
|
if defaultValue != "" {
|
||||||
|
fmt.Printf(" Press Enter for the default (%s).\n", defaultValue)
|
||||||
|
} else if !required {
|
||||||
|
fmt.Println(" Press Enter to leave empty.")
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Enter a %s.\n", kind)
|
fmt.Println()
|
||||||
}
|
}
|
||||||
for {
|
for {
|
||||||
fmt.Printf("%s> ", what)
|
fmt.Printf("%s> ", what)
|
||||||
|
@ -427,7 +432,8 @@ func ChooseOption(o *fs.Option, name string) string {
|
||||||
return ChoosePassword(defaultValue, o.Required)
|
return ChoosePassword(defaultValue, o.Required)
|
||||||
}
|
}
|
||||||
|
|
||||||
what := fmt.Sprintf("%T value", o.Default)
|
what := "value"
|
||||||
|
if o.Default != "" {
|
||||||
switch o.Default.(type) {
|
switch o.Default.(type) {
|
||||||
case bool:
|
case bool:
|
||||||
what = "boolean value (true or false)"
|
what = "boolean value (true or false)"
|
||||||
|
@ -439,6 +445,9 @@ func ChooseOption(o *fs.Option, name string) string {
|
||||||
what = "signed integer"
|
what = "signed integer"
|
||||||
case uint, byte, uint16, uint32, uint64:
|
case uint, byte, uint16, uint32, uint64:
|
||||||
what = "unsigned integer"
|
what = "unsigned integer"
|
||||||
|
default:
|
||||||
|
what = fmt.Sprintf("%T value", o.Default)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var in string
|
var in string
|
||||||
for {
|
for {
|
||||||
|
|
Loading…
Add table
Reference in a new issue