5

There is example: 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

So and by default when I don't use arguments it shows Usage info. I want to use case with no arguments, and also with one [Custom argument] (with custom one I'm getting error: Invalid argument 'regreg')

How can I handle empty and custom arguments here?

nponeccop
  • 13,527
  • 1
  • 44
  • 106
cnd
  • 32,616
  • 62
  • 183
  • 313

1 Answers1

4

A in https://hackage.haskell.org/package/optparse-applicative-0.11.0.2/docs/Options-Applicative-Arrows.html isn't ArrowPlus. I'm not sure if it can be (given that f is Alternative), but for now you have to use Alternative syntax:

subparser (command "foo" ... ...) <|> pure DefaultCommand
phadej
  • 11,947
  • 41
  • 78