fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
d835c5252
master
1# localization: tier1 2# 3# This function is intended to be used as a validation command for individual option specifications 4# given to the `argparse` command. It checks that the argument is a valid integer and optionally 5# whether it is in a reasonable range. 6function _validate_int --no-scope-shadowing 7# Note that we can't use ourself to validate the arguments to the --min and --max flags this 8# function recognizes. 9set -l options'm-min=' 'x-max=' 10argparse -n _argparse_validate_int$options --$argv 11or return 12 13if not string match -qr'^-?\d+$' --$_flag_value 14set -l msg( _ "%s: Value '%s' for flag '%s' is not an integer\n" ) 15printf $msg $_argparse_cmd $_flag_value $_flag_name >&2 16return 1 17end 18 19if set -q _flag_min 20and test $_flag_value -lt $_flag_min 21set -l msg( _ "%s: Value '%s' for flag '%s' less than min allowed of '%s'\n" ) 22printf $msg $_argparse_cmd $_flag_value $_flag_name $_flag_min >&2 23return 1 24end 25 26if set -q _flag_max 27and test $_flag_value -gt $_flag_max 28set -l msg( _ "%s: Value '%s' for flag '%s' greater than max allowed of '%s'\n" ) 29printf $msg $_argparse_cmd $_flag_value $_flag_name $_flag_max >&2 30return 1 31end 32 33return 0 34end