mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-12 13:08:49 +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
|
||||
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
|
||||
or return
|
||||
|
||||
|
@ -14,13 +14,8 @@ function math --description "Perform math calculations in bc"
|
|||
end
|
||||
|
||||
set -l scale 0 # default is integer arithmetic
|
||||
if set -q _flag_scale
|
||||
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
|
||||
set -q _flag_scale
|
||||
and set scale $_flag_scale
|
||||
|
||||
if set -q _flag_val
|
||||
# The expression began with a negative number. Put it back in the expression.
|
||||
|
|
Loading…
Reference in a new issue