Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provide a field that indicates if a value is given for a prompt #244

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions bluemix/terminal/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ type Prompt struct {

Reader io.Reader
Writer io.Writer

ValueProvided bool
}

// NewPrompt returns a single prompt
Expand All @@ -67,6 +69,8 @@ func NewChoicesPrompt(message string, choices []string, options *PromptOptions)

// Resolve reads user input and resolves it to the destination value
func (p *Prompt) Resolve(dest interface{}) error {
p.ValueProvided = false

if len(p.choices) > 0 {
return p.resolveChoices(dest)
}
Expand All @@ -92,6 +96,8 @@ func (p *Prompt) resolveSingle(dest interface{}) error {
err = ErrInputEmpty
}
} else {
p.ValueProvided = true

if p.options.ValidateFunc != nil {
err = p.options.ValidateFunc(input)
}
Expand Down Expand Up @@ -235,6 +241,8 @@ func (p *Prompt) resolveChoices(dest interface{}) error {
err = ErrInputEmpty
}
} else {
p.ValueProvided = true

selectedNum, err = strconv.Atoi(input)
if err != nil {
err = ErrInputNotNumber
Expand Down