我正在删除该帖子,因为没有接受有关审查/编辑的咨询。
答案 0 :(得分:9)
以下是使用Getopt::Long的示例:
use v6;
use Getopt::Long;
my %opt = help => False, 'r=s' => "", 'q=s' => "", 'w=s' => "";
my %options = get-options(%opt).hash;
say %options;
say @*ARGS;
示例运行:
$ p.p6 -w xyz -q def -r abc hello
{help => False, q => def, r => abc, w => xyz}
[hello]
答案 1 :(得分:8)
使用MAIN
sub:
#!/usr/bin/env raku
use v6;
sub MAIN(:$these ="These", :$are="Are", :$params="Params") {
say "$these $are $params";
}
您可以按任何顺序键入以下参数:
./command-line.p6 --are=well --these=those
those well Params
还将捕获任何额外的参数,向您显示实际参数:
./command-line.p6 --are=well --these=those --not=this_one
Usage:
./command-line.p6 [--these=<Any>] [--are=<Any>] [--params=<Any>]
如果您只对带有单横线的参数感兴趣,请you'll need GetOpt::Long as indicated by Hakon