mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 21:44:16 +00:00
update math
to use argparse
This commit is contained in:
parent
140e6204be
commit
e8243af20b
1 changed files with 13 additions and 17 deletions
|
@ -1,24 +1,20 @@
|
||||||
function math --description "Perform math calculations in bc"
|
function math --description "Perform math calculations in bc"
|
||||||
set -l scale 0 # default is integer arithmetic
|
set -l options 'h/help' 's/scale='
|
||||||
|
argparse -n math --min-args=1 $options -- $argv
|
||||||
|
or return
|
||||||
|
|
||||||
if set -q argv[1]
|
if set -q _flag_help
|
||||||
switch $argv[1]
|
|
||||||
case '-s*' # user wants to specify the scale of the output
|
|
||||||
set scale (string replace -- '-s' '' $argv[1])
|
|
||||||
if not string match -q -r '^\d+$' "$scale"
|
|
||||||
echo 'Expected an integer to follow -s' >&2
|
|
||||||
return 2 # missing argument is an error
|
|
||||||
end
|
|
||||||
set -e argv[1]
|
|
||||||
|
|
||||||
case -h --h --he --hel --help
|
|
||||||
__fish_print_help math
|
__fish_print_help math
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
if not set -q argv[1]
|
set -l scale 0 # default is integer arithmetic
|
||||||
return 2 # no arguments is an error
|
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
|
end
|
||||||
|
|
||||||
# Set BC_LINE_LENGTH to a ridiculously high number so it only uses one line for most results.
|
# Set BC_LINE_LENGTH to a ridiculously high number so it only uses one line for most results.
|
||||||
|
|
Loading…
Reference in a new issue