标签: haskell-cmdargs

cmdargs值没有等号的参数

我用来cmdargs为我的Haskell程序编写CLI解析器.

让我们假设这个程序直接来自他们的例子:

{-# LANGUAGE DeriveDataTypeable #-}
import System.Console.CmdArgs.Implicit

data Sample = Sample {hello :: String} deriving (Show, Data, Typeable)

sample = Sample{hello = def &= help "World argument" &= opt "world"}
         &= summary "Sample v1"

main = print =<< cmdArgs sample
Run Code Online (Sandbox Code Playgroud)

如果调用该程序cmdtest.hs,我可以执行

$ runghc cmdtest.hs --hello=world
Sample {hello = "world"}
Run Code Online (Sandbox Code Playgroud)

但是,如果我省略等号(如-o选项中所示gcc -o foo foobar.c),cmdargs会尝试识别world为位置参数

$ runghc cmdtest.hs --hello world
Unhandled argument, none expected: world
Run Code Online (Sandbox Code Playgroud)

是否有任何选项/注释我可以设置为在cmdargs中允许此语法?

更新:使用短选项会暴露同样的问题:

$ runghc cmdtest.hs …
Run Code Online (Sandbox Code Playgroud)

haskell command-line-arguments haskell-cmdargs

7
推荐指数
1
解决办法
323
查看次数