mirror of
https://github.com/rclone/rclone.git
synced 2024-11-25 18:04:55 +01:00
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
@ -101,10 +101,12 @@ func Choose(what string, kind string, choices, help []string, defaultValue strin
|
||||
valueDescription = "your own"
|
||||
}
|
||||
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
|
||||
// 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}
|
||||
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")
|
||||
lines = append(lines, parts...)
|
||||
}
|
||||
lines = append(lines, fmt.Sprintf("%q", text))
|
||||
lines = append(lines, fmt.Sprintf("(%s)", text))
|
||||
pos := i + 1
|
||||
terminal.WriteString(attributes[i%len(attributes)])
|
||||
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
|
||||
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
|
||||
// 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 {
|
||||
fmt.Printf("Enter a %s.\n", kind)
|
||||
fmt.Println()
|
||||
}
|
||||
for {
|
||||
fmt.Printf("%s> ", what)
|
||||
@ -427,7 +432,8 @@ func ChooseOption(o *fs.Option, name string) string {
|
||||
return ChoosePassword(defaultValue, o.Required)
|
||||
}
|
||||
|
||||
what := fmt.Sprintf("%T value", o.Default)
|
||||
what := "value"
|
||||
if o.Default != "" {
|
||||
switch o.Default.(type) {
|
||||
case bool:
|
||||
what = "boolean value (true or false)"
|
||||
@ -439,6 +445,9 @@ func ChooseOption(o *fs.Option, name string) string {
|
||||
what = "signed integer"
|
||||
case uint, byte, uint16, uint32, uint64:
|
||||
what = "unsigned integer"
|
||||
default:
|
||||
what = fmt.Sprintf("%T value", o.Default)
|
||||
}
|
||||
}
|
||||
var in string
|
||||
for {
|
||||
|
Loading…
Reference in New Issue
Block a user