简体   繁体   English

如何在optparse-applicative中获得“剩余参数”?

[英]how to get “leftover arguments” in optparse-applicative?

I am trying to use optparse-applicative. 我正在尝试使用optparse-applicative。 How can I access arguments that are not options? 如何访问不是选项的参数? (From prog --foo --bar=42 baz , I want to get ["baz"] ) (来自prog --foo --bar=42 baz ,我想得到["baz"]

All the the "high level" functions https://hackage.haskell.org/package/optparse-applicative-0.11.0.2/docs/Options-Applicative-Extra.html return a where I want (a,[String]) . 所有“高级”函数https://hackage.haskell.org/package/optparse-applicative-0.11.0.2/docs/Options-Applicative-Extra.html返回我想要a地方(a,[String])

There is some low-level function https://hackage.haskell.org/package/optparse-applicative-0.11.0.2/docs/Options-Applicative-Common.html#v:runParser but I cannot call it directly because of its type. 有一些低级函数https://hackage.haskell.org/package/optparse-applicative-0.11.0.2/docs/Options-Applicative-Common.html#v:runParser但我不能直接调用它因为它的类型。 And indeed I do want to re-use all the plumbing that is in https://hackage.haskell.org/package/optparse-applicative-0.11.0.2/docs/src/Options-Applicative-Extra.html#execParser . 事实上,我确实希望重新使用https://hackage.haskell.org/package/optparse-applicative-0.11.0.2/docs/src/Options-Applicative-Extra.html#execParser中的所有管道。

Positional arguments are part of the parser specification. 位置参数是解析器规范的一部分。 They are not returned separately by the function that runs the parser. 它们不会由运行解析器的函数单独返回。 The functions argument and strArgument can be used to add a parser for a positional argument to the specification. 函数argumentstrArgument可用于为规范的位置参数添加解析器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM