Skip to content

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

Open
dpopp07 wants to merge 2 commits intoIBM-Cloud:masterfrom
dpopp07:dp/prompt-check-value-provided
Open

provide a field that indicates if a value is given for a prompt#244
dpopp07 wants to merge 2 commits intoIBM-Cloud:masterfrom
dpopp07:dp/prompt-check-value-provided

Conversation

@dpopp07
Copy link
Copy Markdown

@dpopp07 dpopp07 commented Mar 26, 2021

I have a use case in writing CLI plugins that is not explicitly supported by the SDK. When accepting input interactively, using the Prompt function, I would like a way to be able to determine if the user provided a value or not.

For example - say I prompt for an optional, boolean value. If the user skips the prompt, i.e. they just press "Enter", I would like to take one path and if the user enters "n", I would like to take another path. Currently, it is not simple to distinguish between the two.

This PR adds a single field to the Prompt type, ValueProvided, that will be set to true if the user provides any input and will remain false if the input is empty. The type is public so that it can be accessed by the developer using the SDK.

I am planning to write tests/documentation for this change but first, I want to see what your thoughts on this change are. Is this something you would be willing to add to the package?

EDIT: This can be accomplished using the ValidateFunc option for the prompt, but it requires a lot of extra code. It would be nice for this to be simpler to determine.

@archerzz
Copy link
Copy Markdown
Contributor

IMHO, this is a responsibility of command parsing framework. Popular frameworks provide capability of simple validation, like:

@dpopp07
Copy link
Copy Markdown
Author

dpopp07 commented Mar 31, 2021

I agree with you for parsing commands but I'm specifically talking about the Prompt functionality that you expose in this library, in the terminal package - https://pkg.go.dev/github.com/IBM-Cloud/ibm-cloud-cli-sdk@v0.6.7/bluemix/terminal#Prompt

@Aerex Aerex requested a review from steveclay as a code owner October 5, 2022 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants