如何在子主机中获得强制性命名参数?
这是我能得到的最好的:
sub MAIN(Int :p($parm)!)
{
say "* parm=", $parm;
}
但是:
$ raku test-par.raku
Usage:
test-par.raku -p[=Int]
它说参数是可选的!
确实是:
$ raku test-par.raku -p
* parm=True
那么,什么给了?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
bool
也恰好是int
:因为
-p
是bool
它也是int
:该参数仍然是可选的;
-p
刚刚(可以说是不直觉)的处理,例如-p = 1
。不幸的是,要实际执行所请求的约束将需要添加一个额外的过滤器:A
Bool
also happens to be anInt
:Because
-p
is aBool
it is also anInt
:The parameter is still optional;
-p
is just being treated (arguably unintuitively) like-p=1
. To actually enforce the requested constraint would unfortunately require adding an additional filter:正如其他一些问题所述
true
是enum
,值1
,所以它是int
,如果要确保始终以一个值调用-p
您可以使用 args to to to to to 功能在之前检查传入的参数 它们被传递给main。类似:这里我们检查至少一个参数是
-p
,并且它也具有整数值。您还可以通过添加生成 - 使用如果要在输出中更改其显示-p
的方式。As some other questions have said
True
is anEnum
with value of1
so it's andInt
if you want to ensure the-p
is always called with a value you can use the ARGS-TO-CAPTURE function to check the incoming arguments before they are passed to main. Something like :Here we check that at least one of the arguments is
-p
and it has also got an integer value. You can also override the$*USAGE
value by adding the GENERATE-USAGE sub if you want to change how it displays-p
in the output.首先,感谢您的答案和评论。
对于我的特定异想天开,这是我可以做到的最好的:
据我所知,它可以处理简短和长期的选择,并使选项必须进行。
First of all, thanks for the answers and comments.
For my specific whims, this is the best I could come to:
As far as I can see, it handles short and long options, and makes the options mandatory.