feat(flags,command): skip optional options and arguments that have an empty string as value #805
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.
resolves #731
fixes #665
This pull request improves the handling of optional arguments and options.
Optional arguments and options with an empty string as their value are now skipped and set to
undefined.Assuming that the option
--foois an optional option, the commandmy-cli --foo="" --bar="123"would be equivalent tomy-cli --bar="123".This makes it easier to use commands in scripts that accept conditional arguments without having to parse them manually.
Example: If the following command is executed:
my-cli --optional-option "$MY_ENV_VAR"andMY_ENV_VARis not defined, the option--optional-optionis ignored and treated as not defined.This also applies to arguments. Arguments defined as follows
[foo] [bar] [...baz]and called as followsmy-cli "foo-value" "" "baz-value-1" "" "baz-value-3", are parsed to"foo-value", undefined, "baz-value-1", "baz-value-3"`.Single arguments with a
""as their value are set toundefined, and rest arguments with a""as their value are ignored.