首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在没有fish解析的fish shell中解析参数

在没有fish解析的fish shell中解析参数
EN

Stack Overflow用户
提问于 2021-12-31 18:39:28
回答 1查看 182关注 0票数 1

我正在使用fish shell,并编写了自己的小解析器函数,因为我发现and解析令人困惑。基本上,如果一个标志是匹配的,它将使用以下参数中的信息。但是,我假设我的方法必须引入bug,因为我还没有看到这种方法在网上使用。使用Are解析是否有我所缺少的优点?

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-12-31 21:10:29

在With解析中:

代码语言:javascript
复制
# 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_output
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70544890

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档