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

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

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

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

最佳答案
https://hackage.haskell.org/package/optparse-applicative-0.11.0.2/docs/Options-Applicative-Arrows.html中的A不是
ArrowPlus.我不确定它是否可以(假设f是Alternative),但是现在你必须使用Alternative语法:

subparser (command "foo" ... ...) <|> pure DefaultCommand
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞