implement a new implicit int option spec

While updating the `history` function to use `argparse` I realized it is
useful to define an option that can be used in three ways. First by
using the short flag; e.g., `-n NNN`. Second by using the long flag;
e.g., `--max NNN`. Third, as an implicit int flag; e.g., `-NNN`. This
use case is now supported by a spec of the form `n#max`.
This commit is contained in:
Kurtis Rader
2017-07-16 18:27:41 -07:00
parent 06d071dd94
commit 3e226f0a5e
6 changed files with 78 additions and 10 deletions

View File

@@ -37,6 +37,18 @@ argparse '#-val=' -- abc -x def
echo '# Invalid arg in the face of a "#-val" spec' >&2
argparse '#-val' -- abc -x def
echo '# Defining a short flag more than once' >&2
argparse 's/short' 'x/xray' 's/long' -- -s -x --long
echo '# Defining a long flag more than once' >&2
argparse 's/short' 'x/xray' 'l/short' -- -s -x --long
echo '# Defining an implicit int flag more than once' >&2
argparse '#-val' 'x/xray' 'v#val' -- -s -x --long
echo '# Defining an implicit int flag with modifiers' >&2
argparse 'v#val=' --
##########
# Now verify that validly formed invocations work as expected.
@@ -71,8 +83,18 @@ begin
show $argv
end
echo '# A "#-val" spec works'
echo '# Implicit int flags work'
for v in (set -l -n); set -e $v; end
argparse '#-val' -- abc -123 def
set -l
for v in (set -l -n); set -e $v; end
argparse 'v/verbose' '#-val' 't/token=' -- -123 a1 --token woohoo --234 -v a2 --verbose
set -l
echo '# Should be set to 987'
for v in (set -l -n); set -e $v; end
argparse 'm#max' -- argle -987 bargle
set -l
echo '# Should be set to 765'
for v in (set -l -n); set -e $v; end
argparse 'm#max' -- argle -987 bargle --max 765
set -l