@@ -145,8 +145,8 @@ func (c *Context) getFromFlag(name, ftype, desc string, def interface{}) (interf
145145 return nil , nil
146146}
147147
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 {
150150 if v == nil {
151151 return true
152152 }
@@ -177,7 +177,8 @@ func parseBool(text string) (bool, error) {
177177 return v > 0 , err
178178}
179179
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 ) {
181182 def , label := "" , ""
182183 if len (optional ) > 0 {
183184 def = fmt .Sprintf ("%v" , optional [0 ])
@@ -186,7 +187,7 @@ func (c *Context) prompt(prompt, ftype string, optional ...interface{}) (interfa
186187 }
187188 }
188189
189- input := bufio .NewReader (c . input )
190+ input := bufio .NewReader (in )
190191 fmt .Fprintf (os .Stderr , "%s %s: " , prompt , label )
191192 text , _ := input .ReadString ('\n' )
192193 text = strings .Trim (text , " \t \n " )
@@ -255,11 +256,11 @@ func (c *Context) Funcs() []template.Function {
255256 }
256257 // The last value in the optional var args is the value from the previous
257258 // pipeline.
258- if len (optional ) > 0 && ! missing (ftype , optional [len (optional )- 1 ]) {
259+ if len (optional ) > 0 && ! Missing (ftype , optional [len (optional )- 1 ]) {
259260 return optional [len (optional )- 1 ], nil
260261 }
261262
262- return c . prompt ( prompt , ftype , optional ... )
263+ return Prompt ( c . input , prompt , ftype , optional ... )
263264 },
264265 },
265266 }
0 commit comments