mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 21:03:12 +00:00
3e226f0a5e
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`.
53 lines
839 B
Text
53 lines
839 B
Text
# No args
|
|
# One arg and no matching flags
|
|
argv help
|
|
count=1
|
|
|help|
|
|
# Five args with two matching a flag
|
|
_flag_h 2
|
|
_flag_help 2
|
|
argv 'help' 'me' 'a lot more'
|
|
count=3
|
|
|help|
|
|
|me|
|
|
|a lot more|
|
|
# Required, optional, and multiple flags
|
|
_flag_a ABC
|
|
_flag_abc ABC
|
|
_flag_d
|
|
_flag_def
|
|
_flag_g 'g1' 'g2' 'g3'
|
|
_flag_ghk 'g1' 'g2' 'g3'
|
|
_flag_h 1
|
|
_flag_help 1
|
|
argv 'help' 'me'
|
|
count=2
|
|
|help|
|
|
|me|
|
|
# --stop-nonopt works
|
|
_flag_a A2
|
|
_flag_abc A2
|
|
_flag_h 1
|
|
_flag_help 1
|
|
argv 'non-opt' 'second non-opt' '--help'
|
|
count=3
|
|
|non-opt|
|
|
|second non-opt|
|
|
|--help|
|
|
# Implicit int flags work
|
|
_flag_val 123
|
|
argv 'abc' 'def'
|
|
_flag_t woohoo
|
|
_flag_token woohoo
|
|
_flag_v 2
|
|
_flag_val -234
|
|
_flag_verbose 2
|
|
argv 'a1' 'a2'
|
|
# Should be set to 987
|
|
_flag_m 987
|
|
_flag_max 987
|
|
argv 'argle' 'bargle'
|
|
# Should be set to 765
|
|
_flag_m 765
|
|
_flag_max 765
|
|
argv 'argle' 'bargle'
|