@@ -145,8 +145,8 @@ func (c *Context) getFromFlag(name, ftype, desc string, def interface{}) (interf
145
145
return nil , nil
146
146
}
147
147
148
- // returns true if the value v is missing of the type t
149
- func missing (t string , v interface {}) bool {
148
+ // Missing returns true if the value v is missing of the type t
149
+ func Missing (t string , v interface {}) bool {
150
150
if v == nil {
151
151
return true
152
152
}
@@ -177,7 +177,8 @@ func parseBool(text string) (bool, error) {
177
177
return v > 0 , err
178
178
}
179
179
180
- func (c * Context ) prompt (prompt , ftype string , optional ... interface {}) (interface {}, error ) {
180
+ // Prompt handles prompting the user using the given prompt message, type string and optional values.
181
+ func Prompt (in io.Reader , prompt , ftype string , optional ... interface {}) (interface {}, error ) {
181
182
def , label := "" , ""
182
183
if len (optional ) > 0 {
183
184
def = fmt .Sprintf ("%v" , optional [0 ])
@@ -186,7 +187,7 @@ func (c *Context) prompt(prompt, ftype string, optional ...interface{}) (interfa
186
187
}
187
188
}
188
189
189
- input := bufio .NewReader (c . input )
190
+ input := bufio .NewReader (in )
190
191
fmt .Fprintf (os .Stderr , "%s %s: " , prompt , label )
191
192
text , _ := input .ReadString ('\n' )
192
193
text = strings .Trim (text , " \t \n " )
@@ -255,11 +256,11 @@ func (c *Context) Funcs() []template.Function {
255
256
}
256
257
// The last value in the optional var args is the value from the previous
257
258
// pipeline.
258
- if len (optional ) > 0 && ! missing (ftype , optional [len (optional )- 1 ]) {
259
+ if len (optional ) > 0 && ! Missing (ftype , optional [len (optional )- 1 ]) {
259
260
return optional [len (optional )- 1 ], nil
260
261
}
261
262
262
- return c . prompt ( prompt , ftype , optional ... )
263
+ return Prompt ( c . input , prompt , ftype , optional ... )
263
264
},
264
265
},
265
266
}
0 commit comments