diff --git a/cmd/incus/main.go b/cmd/incus/main.go index bc435fe0672..d13c63b215e 100644 --- a/cmd/incus/main.go +++ b/cmd/incus/main.go @@ -417,7 +417,7 @@ func (c *cmdGlobal) PreRun(cmd *cobra.Command, args []string) error { // Setup password helper c.conf.PromptPassword = func(filename string) (string, error) { - return ask.AskPasswordOnce(fmt.Sprintf(i18n.G("Password for %s: "), filename)), nil + return c.asker.AskPasswordOnce(fmt.Sprintf(i18n.G("Password for %s: "), filename)), nil } // If the user is running a command that may attempt to connect to the local daemon diff --git a/shared/ask/ask.go b/shared/ask/ask.go index 0b1c6c2cb11..0f43f1453e9 100644 --- a/shared/ask/ask.go +++ b/shared/ask/ask.go @@ -56,7 +56,7 @@ func (a *Asker) AskChoice(question string, choices []string, defaultAnswer strin } // AskInt asks the user to enter an integer between a min and max value. -func (a *Asker) AskInt(question string, min int64, max int64, defaultAnswer string, validate func(int64) error) (int64, error) { +func (a *Asker) AskInt(question string, minValue int64, maxValue int64, defaultAnswer string, validate func(int64) error) (int64, error) { for { answer, err := a.askQuestion(question, defaultAnswer) if err != nil { @@ -69,7 +69,7 @@ func (a *Asker) AskInt(question string, min int64, max int64, defaultAnswer stri continue } - if !((min == -1 || result >= min) && (max == -1 || result <= max)) { + if !((minValue == -1 || result >= minValue) && (maxValue == -1 || result <= maxValue)) { fmt.Fprintf(os.Stderr, "Invalid input: out of range\n\n") continue } @@ -96,9 +96,9 @@ func (a *Asker) AskString(question string, defaultAnswer string, validate func(s } if validate != nil { - error := validate(answer) - if error != nil { - fmt.Fprintf(os.Stderr, "Invalid input: %s\n\n", error) + err := validate(answer) + if err != nil { + fmt.Fprintf(os.Stderr, "Invalid input: %s\n\n", err) continue } @@ -114,6 +114,12 @@ func (a *Asker) AskString(question string, defaultAnswer string, validate func(s } // AskPassword asks the user to enter a password. +func (a *Asker) AskPassword(question string) string { + return AskPassword(question) +} + +// AskPassword asks the user to enter a password. +// Deprecated: Use asker.AskPassword instead. func AskPassword(question string) string { for { fmt.Print(question) @@ -141,6 +147,14 @@ func AskPassword(question string) string { // AskPasswordOnce asks the user to enter a password. // // It's the same as AskPassword, but it won't ask to enter it again. +func (a *Asker) AskPasswordOnce(question string) string { + return AskPasswordOnce(question) +} + +// AskPasswordOnce asks the user to enter a password. +// +// It's the same as AskPassword, but it won't ask to enter it again. +// Deprecated: Use asker.AskPasswordOnce instead. func AskPasswordOnce(question string) string { for { fmt.Print(question)