From 69ecda50829f8fb016b515b8ff5c8b2b1a7dbdf8 Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Tue, 18 Jul 2017 15:03:08 -0700 Subject: [PATCH] update `math` to use the new argparse validation --- share/functions/math.fish | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/share/functions/math.fish b/share/functions/math.fish index efcdf9757..dba3a7982 100644 --- a/share/functions/math.fish +++ b/share/functions/math.fish @@ -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.