mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-01 10:11:14 -03:00
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:
@@ -156,7 +156,9 @@ Each option specification consists of:
|
||||
|
||||
- Optionally a ``&``, indicating that the option and any attached values are not to be saved in ``$argv`` or ``$argv_opts``. This does not affect the the ``_flag_`` variables.
|
||||
|
||||
- Optionally a ``!`` followed by fish script to validate the value. Typically this will be a function to run. If the exit status is zero the value for the flag is valid. If non-zero the value is invalid. Any error messages should be written to stdout (not stderr). See the section on :ref:`Flag Value Validation <flag-value-validation>` for more information.
|
||||
- Nothing if the flag is a boolean that takes no argument, or
|
||||
|
||||
- ``!`` followed by fish script to validate the value. Typically this will be a function to run. If the exit status is zero the value for the flag is valid. If non-zero the value is invalid. Any error messages should be written to stdout (not stderr). See the section on :ref:`Flag Value Validation <flag-value-validation>` for more information.
|
||||
|
||||
See the :doc:`fish_opt <fish_opt>` command for a friendlier but more verbose way to create option specifications.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user