You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Boolean options should not swallow the following argument if it is false or true. This can occur coincidentally and is probably not what the user wants.
Consider a CLI tool that outputs the size of files, where each file is passed as a positional argument. The -h or --human flag causes it to output human-friendly values. ("1KB" instead of "1024")
$ file-sizes -h *
file-1 1MB
file-2 2.3MB
Now imagine that the files in CWD are "false", "foo", and "bar"
$ file-sizes -h *
foo 1035
bar 345
# Errors: -h flag isn't set; "false" is omitted
For this reason, boolean options should never interpret the following argument as their value.
# following positional argument should *never* be interpreted as a value for the `--human` flag
file-sizes --human true
Users can still pass --human, --no-human, --human=true, or --human=false to explicitly set the flag to true or false.
The text was updated successfully, but these errors were encountered:
darcyclarke
changed the title
Boolean arg swallows following arg if it is false or true
[BUG] Boolean arg swallows following arg if it is false or trueJul 28, 2022
Boolean options should not swallow the following argument if it is
false
ortrue
. This can occur coincidentally and is probably not what the user wants.Consider a CLI tool that outputs the size of files, where each file is passed as a positional argument. The
-h
or--human
flag causes it to output human-friendly values. ("1KB" instead of "1024")Now imagine that the files in CWD are "false", "foo", and "bar"
For this reason, boolean options should never interpret the following argument as their value.
Users can still pass
--human
,--no-human
,--human=true
, or--human=false
to explicitly set the flag to true or false.The text was updated successfully, but these errors were encountered: