provide a field that indicates if a value is given for a prompt #244
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.