limit input retries

Prevent going into a busy loop if the input fd closes early.
This commit is contained in:
James Bardin 2016-07-27 21:34:30 -04:00
parent b4b70193d2
commit 341abd7956
1 changed files with 7 additions and 1 deletions

View File

@ -332,6 +332,7 @@ func (c *Context) Input(mode InputMode) error {
// Ask the user for a value for this variable // Ask the user for a value for this variable
var value string var value string
retry := 0
for { for {
var err error var err error
value, err = c.uiInput.Input(&InputOpts{ value, err = c.uiInput.Input(&InputOpts{
@ -345,7 +346,12 @@ func (c *Context) Input(mode InputMode) error {
} }
if value == "" && v.Required() { if value == "" && v.Required() {
// Redo if it is required. // Redo if it is required, but abort if we keep getting
// blank entries
if retry > 2 {
return fmt.Errorf("missing required value for %q", n)
}
retry++
continue continue
} }