MCPcopy
hub / github.com/lxc/incus / AskString

Method AskString

shared/ask/ask.go:91–114  ·  view source on GitHub ↗

AskString asks the user to enter a string, which optionally conforms to a validation function.

(question string, defaultAnswer string, validate func(string) error)

Source from the content-addressed store, hash-verified

89// AskString asks the user to enter a string, which optionally
90// conforms to a validation function.
91func (a *Asker) AskString(question string, defaultAnswer string, validate func(string) error) (string, error) {
92 for {
93 answer, err := a.askQuestion(question, defaultAnswer)
94 if err != nil {
95 return "", err
96 }
97
98 if validate != nil {
99 err := validate(answer)
100 if err != nil {
101 fmt.Fprintf(os.Stderr, "Invalid input: %s\n\n", err)
102 continue
103 }
104
105 return answer, err
106 }
107
108 if len(answer) != 0 {
109 return answer, err
110 }
111
112 invalidInput()
113 }
114}
115
116// AskPassword asks the user to enter a password.
117func (a *Asker) AskPassword(question string) string {

Callers 15

runMethod · 0.95
runMethod · 0.95
askNetworkingMethod · 0.80
askStoragePoolMethod · 0.80
askDaemonMethod · 0.80
runMethod · 0.80
runMethod · 0.80
askClusteringFunction · 0.80
askTargetMethod · 0.80
askPathMethod · 0.80
askServerMethod · 0.80
gatherInfoMethod · 0.80

Calls 2

askQuestionMethod · 0.95
invalidInputFunction · 0.85

Tested by

no test coverage detected