【发布时间】:2014-03-26 22:33:30
【问题描述】:
我使用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
如果这个程序叫cmdtest.hs,我可以执行
$ runghc cmdtest.hs --hello=world
Sample {hello = "world"}
但是,如果我不使用等号(如在 gcc -o foo foobar.c 中的 -o 选项中),cmdargs 会尝试将 world 识别为位置参数
$ runghc cmdtest.hs --hello world
Unhandled argument, none expected: world
我可以设置任何选项/注释以允许在 cmdargs 中使用此语法吗?
更新:使用 short 选项会暴露同样的问题:
$ runghc cmdtest.hs -h world
Unhandled argument, none expected: world
更新 2: cmdargs Explicit 模块中的 FlagInfo data 似乎表明它是有可能的,至少如果使用 Explicit 而不是 Implicit
【问题讨论】:
标签: haskell command-line-arguments haskell-cmdargs