Make argparse reject supplying a validator for boolean flags

Specifically, this commit simply makes argparse issue an error if you use the !
syntax to define a validation script on an option that does not take any
arguments. For example, "argparse foo!exit -- --foo" is now an error. This was
previously accepted, despite that fact that the code after ! would never be
executed (the ! code is only executed when an option is given a value).

Alternatively, ! validation scripts could be made to execute even when no value
was provided, but this break existing code that uses them with flags that take
optional values.
This commit is contained in:
Isaac Oscar Gariano
2025-08-03 10:07:08 +10:00
parent c403822fac
commit 007edac145
3 changed files with 16 additions and 1 deletions

View File

@@ -678,6 +678,11 @@ begin
#CHECKERR: (Type 'help argparse' for related documentation)
end
begin
argparse f!echo hello -- -f
#CHECKERR: argparse: Invalid option spec 'f!echo' at char '!'
end
begin
argparse --ignore-unknown h i -- -hoa -oia
echo -- $argv