mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-26 11:45:08 +00:00
update math
to use the new argparse validation
This commit is contained in:
parent
4e1303823b
commit
69ecda5082
1 changed files with 3 additions and 8 deletions
|
@ -4,7 +4,7 @@ function math --description "Perform math calculations in bc"
|
||||||
set argv -- $argv
|
set argv -- $argv
|
||||||
end
|
end
|
||||||
|
|
||||||
set -l options 'h/help' 's/scale=' '#-val'
|
set -l options 'h/help' 's/scale=!_validate_int --min=0' '#-val'
|
||||||
argparse -n math --stop-nonopt --min-args=1 $options -- $argv
|
argparse -n math --stop-nonopt --min-args=1 $options -- $argv
|
||||||
or return
|
or return
|
||||||
|
|
||||||
|
@ -14,13 +14,8 @@ function math --description "Perform math calculations in bc"
|
||||||
end
|
end
|
||||||
|
|
||||||
set -l scale 0 # default is integer arithmetic
|
set -l scale 0 # default is integer arithmetic
|
||||||
if set -q _flag_scale
|
set -q _flag_scale
|
||||||
set scale $_flag_scale
|
and set scale $_flag_scale
|
||||||
if not string match -q -r '^\d+$' "$scale"
|
|
||||||
printf (_ "%s: Expected an integer to follow --scale") math >&2
|
|
||||||
return 2 # missing argument is an error
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if set -q _flag_val
|
if set -q _flag_val
|
||||||
# The expression began with a negative number. Put it back in the expression.
|
# The expression began with a negative number. Put it back in the expression.
|
||||||
|
|
Loading…
Reference in a new issue