fix: return a cancel flag if a user cancels a prompt #139
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.
issue
When executing
Argument.runSeparate
, provided arguments are pushed into an array, but if a user provides an incorrect argument type and cancels the prompt, a cancelFlag
is generated but it's pushed into the array. Since theflag
is in anArray
,Argument.isShortCircuit
returns false and the command executes, even though the user cancelled.example
If the
args
array for a command is:and you execute the command with:
As the arguments aren't numbers, the user will be prompted to provide a valid argument for each invalid argument. So they're prompted to provide a number for
not_a_number1
, and if theycancel
, the client will respond with the cancel text, and then respond with theretry
text to provide a valid argument fornot_a_number2
, and if the user enterscancel
again, the command executes with theargs
object as:solution
To fix this,
Argument.runSeparate
asks the user for a valid argument, and if the user cancels, the method returns the flag, otherwise, the response is pushed into the array.This allows
Argument.isShortCircuit
to successfully determine if the given flag is a cancel flag.