From f9635b1a04465cb019c106958ee5e55a020f250c Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Sun, 15 Sep 2024 09:35:18 +0200 Subject: [PATCH] docs/argparse: Explain dashes in flag names --- doc_src/cmds/argparse.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc_src/cmds/argparse.rst b/doc_src/cmds/argparse.rst index 14b749b0d..49febc7f0 100644 --- a/doc_src/cmds/argparse.rst +++ b/doc_src/cmds/argparse.rst @@ -78,6 +78,8 @@ To use the flags argparse has extracted:: set -ql _flag_name[1] and set myname $_flag_name[-1] # here we use the *last* --name= +Any characters in the flag name that are not valid in a variable name (like ``-`` dashes) will be replaced with underscores. + The ``--`` argument is required. You do not have to include any option specifications or arguments after the ``--`` but you must include the ``--``. For example, this is acceptable:: set -l argv foo @@ -248,6 +250,13 @@ After this it figures out which variable it should operate on according to the ` set -q _flag_path and set var PATH + # ... + + # Check for --dry-run. + # The "-" has been replaced with a "_" because + # it is not valid in a variable name + not set -ql _flag_dry_run + and set $var $result Limitations