4

有例子: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':)

我如何在这里处理空参数和自定义参数?

4

1 回答 1

3

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

subparser (command "foo" ... ...) <|> pure DefaultCommand
于 2015-07-11T09:41:46.107 回答