fish-shell/tests/fish_opt.in
Kurtis Rader a4dc2b872b implement fish_opt helper command
This implements a `fish_opt` command that provides a way for people
to create option specs for the `argparse` command as an alternative to
creating such strings by hand.

Fixes #4190
2017-07-12 22:38:32 -07:00

63 lines
1.9 KiB
Fish

# Start by testing a bunch of error conditions.
echo '# no args is an error' >&2
fish_opt
and echo unexpected status $status
echo '# no short flag or an invalid short flag is an error' >&2
fish_opt -l help
and echo unexpected status $status
fish_opt -s help
and echo unexpected status $status
echo '# a required and optional arg makes no sense' >&2
fish_opt -s h -l help -r --optional-val
and echo unexpected status $status
echo '# a repeated and optional arg makes no sense' >&2
fish_opt -s h -l help --multiple-vals --optional-val
and echo unexpected status $status
echo '# an unexpected arg not associated with a flag is an error' >&2
fish_opt -s h -l help hello
and echo unexpected status $status
# Now verify that valid combinations of options produces the correct output.
echo '# bool, short only'
fish_opt -s h
or echo unexpected status $status
echo '# bool, short and long'
fish_opt --short h --long help
or echo unexpected status $status
echo '# bool, short and long but the short var cannot be used'
fish_opt --short h --long help --long-only
echo '# required val, short and long but the short var cannot be used'
fish_opt --short h --long help -r --long-only
or echo unexpected status $status
echo '# optional val, short and long valid'
fish_opt --short h -l help --optional-val
or echo unexpected status $status
echo '# optional val, short and long but the short var cannot be used'
fish_opt --short h -l help --optional-val --long-only
or echo unexpected status $status
echo '# repeated val, short and long valid'
fish_opt --short h -l help --multiple-vals
or echo unexpected status $status
echo '# repeated val, short and long but short not valid'
fish_opt --short h -l help --multiple-vals --long-only
or echo unexpected status $status
echo '# repeated val, short only'
fish_opt -s h --multiple-vals
or echo unexpected status $status
fish_opt -s h --multiple-vals --long-only
or echo unexpected status $status