Skip to content

Conversation

@c4spar
Copy link
Owner

@c4spar c4spar commented Aug 21, 2025

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 --foo is an optional option, the command my-cli --foo="" --bar="123" would be equivalent to my-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" and MY_ENV_VAR is not defined, the option --optional-option is ignored and treated as not defined.

This also applies to arguments. Arguments defined as follows [foo] [bar] [...baz] and called as follows my-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 to undefined, and rest arguments with a "" as their value are ignored.

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.

Cliffy should allow to pass option with empty value if option is declared as optional. Empty strings are parsed as arguments regardless of context

2 participants