我正在使用fish shell,并编写了自己的小解析器函数,因为我发现and解析令人困惑。基本上,如果一个标志是匹配的,它将使用以下参数中的信息。但是,我假设我的方法必须引入bug,因为我还没有看到这种方法在网上使用。使用Are解析是否有我所缺少的优点?
function check_args
for current_arg in (seq 1 (count $argv))
#grab next argument
set next_arg $argv[(math $current_arg + 1)]
switch $argv[$current_arg]
case -h --help
usage
break
case -t --theme
echo "theme: " $next_arg
set -g theme themes/$next_arg.css
case -f --format
echo "format: " $next_arg
set -g format $next_arg
case -o --output
echo "output: " $next_arg
set -g output $next_arg
end
end
end
check_args $argv #calls the function with the passed arguments发布于 2021-12-31 21:10:29
在With解析中:
# the -- is required!
argparse h/help t/theme= f/format= o/output= -- $argv
or exit 1
# just to inspect the variables
set -S _flag_h _flag_help _flag_t _flag_theme _flag_f _flag_format _flag_o _flag_output
if set -q _flag_help
usage
exit
end
set theme themes/$_flag_theme.css
set format $_flag_format
set output $_flag_outputhttps://stackoverflow.com/questions/70544890
复制相似问题