haskell - optparse-applicative:如何处理 Arrow 语法中的无参数情况

标签 haskell command-line-arguments applicative arrows optparse-applicative

有例子:https://github.com/pcapriotti/optparse-applicative/blob/master/tests/Examples/Cabal.hs#L46-L62

parser :: Parser Args
parser = runA $ proc () -> do
  opts <- asA commonOpts -< ()
  cmds <- (asA . hsubparser)
            ( command "install"
              (info installParser
                    (progDesc "Installs a list of packages"))
           <> command "update"
              (info updateParser
                    (progDesc "Updates list of known packages"))
           <> command "configure"
              (info configureParser
                    (progDesc "Prepare to build the package"))
           <> command "build"
              (info buildParser
                    (progDesc "Make this package ready for installation")) ) -< ()
  A version >>> A helper -< Args opts cmds

...
pinfo :: ParserInfo Args
pinfo = info parser
  ( progDesc "An example modelled on cabal" )

main :: IO ()
main = do
  r <- execParser pinfo
  print r

因此,默认情况下,当我不使用参数时,它会显示使用信息。我想使用没有参数的案例,还有一个 [自定义参数](自定义一个我收到错误: Invalid argument 'regreg' )

如何在此处处理空参数和自定义参数?

最佳答案

Ahttps://hackage.haskell.org/package/optparse-applicative-0.11.0.2/docs/Options-Applicative-Arrows.html不是 ArrowPlus .我不确定它是否可以(假设 fAlternative ),但现在你必须使用 Alternative句法:

subparser (command "foo" ... ...) <|> pure DefaultCommand

关于haskell - optparse-applicative:如何处理 Arrow 语法中的无参数情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31318643/

相关文章:

haskell - 为什么:p freeze in GHCi when I give it this corecursive value?

haskell - 禁止某些 Haskell Alex/Happy 编译消息

c++ - 如何在 C++ 中将命令行字符串转换为 hwnd?

haskell - "lax"在 "lax monoidal functor"中是什么意思?

scala - 如何使用 Name 作为应用程序?

haskell - 获取函数的地址(不与 C 接口(interface))

haskell - Elixir 的算术级数范围

windows - Raku:带空格的 shell 调用的语法是什么?

Python:命令行参数的传递方式与硬编码行不同

haskell - 为什么<*>中的函数为Nothing时Maybe的Applicative实例不给出任何内容