mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 16:34:30 +01:00
config: fix issue where required password options had to be re-entered when editing existing remote
See #5551
This commit is contained in:
parent
38e2f835ed
commit
3641727edb
@ -200,13 +200,17 @@ func Enter(what string, kind string, defaultValue string, required bool) string
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ChoosePassword asks the user for a password
|
// ChoosePassword asks the user for a password
|
||||||
func ChoosePassword(required bool) string {
|
func ChoosePassword(defaultValue string, required bool) string {
|
||||||
fmt.Printf("Choose an alternative below.")
|
fmt.Printf("Choose an alternative below.")
|
||||||
actions := []string{"yYes type in my own password", "gGenerate random password"}
|
actions := []string{"yYes, type in my own password", "gGenerate random password"}
|
||||||
defaultAction := -1
|
defaultAction := -1
|
||||||
if !required {
|
if defaultValue != "" {
|
||||||
defaultAction = len(actions)
|
defaultAction = len(actions)
|
||||||
actions = append(actions, "nNo leave this optional password blank")
|
actions = append(actions, "nNo, keep existing")
|
||||||
|
fmt.Printf(" Press Enter for the default (%s).", string(actions[defaultAction][0]))
|
||||||
|
} else if !required {
|
||||||
|
defaultAction = len(actions)
|
||||||
|
actions = append(actions, "nNo, leave this optional password blank")
|
||||||
fmt.Printf(" Press Enter for the default (%s).", string(actions[defaultAction][0]))
|
fmt.Printf(" Press Enter for the default (%s).", string(actions[defaultAction][0]))
|
||||||
}
|
}
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
@ -232,7 +236,7 @@ func ChoosePassword(required bool) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 'n':
|
case 'n':
|
||||||
return ""
|
return defaultValue
|
||||||
default:
|
default:
|
||||||
fs.Errorf(nil, "Bad choice %c", i)
|
fs.Errorf(nil, "Bad choice %c", i)
|
||||||
}
|
}
|
||||||
@ -412,8 +416,15 @@ func ChooseOption(o *fs.Option, name string) string {
|
|||||||
fmt.Println(help)
|
fmt.Println(help)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var defaultValue string
|
||||||
|
if o.Default == nil {
|
||||||
|
defaultValue = ""
|
||||||
|
} else {
|
||||||
|
defaultValue = fmt.Sprint(o.Default)
|
||||||
|
}
|
||||||
|
|
||||||
if o.IsPassword {
|
if o.IsPassword {
|
||||||
return ChoosePassword(o.Required)
|
return ChoosePassword(defaultValue, o.Required)
|
||||||
}
|
}
|
||||||
|
|
||||||
what := fmt.Sprintf("%T value", o.Default)
|
what := fmt.Sprintf("%T value", o.Default)
|
||||||
@ -430,13 +441,6 @@ func ChooseOption(o *fs.Option, name string) string {
|
|||||||
what = "unsigned integer"
|
what = "unsigned integer"
|
||||||
}
|
}
|
||||||
var in string
|
var in string
|
||||||
var defaultValue string
|
|
||||||
if o.Default == nil {
|
|
||||||
defaultValue = ""
|
|
||||||
} else {
|
|
||||||
defaultValue = fmt.Sprint(o.Default)
|
|
||||||
}
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
if len(o.Examples) > 0 {
|
if len(o.Examples) > 0 {
|
||||||
var values []string
|
var values []string
|
||||||
|
Loading…
Reference in New Issue
Block a user