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

Conversation

dpopp07
Copy link

@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
Contributor

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

@dpopp07
Copy link
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/[email protected]/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