Questions tagged [optparse-applicative]

The `optparse-applicative` package contains utilities and combinators to define command line option parsers.

optparse-applicative

`

37 questions
27
votes
1 answer

How to parse an optional flag as a Maybe value?

I'm trying to use optparse-applicative to parse a Maybe String but I can't find anywhere how to deal with Maybe. The only thing I found is to add a default value but I really need a Nothing if user didn't supply an option instead of "". Is there any…
mb14
  • 22,276
  • 7
  • 60
  • 102
18
votes
1 answer

Generate optparse-applicative parser from free alternative functor

Consider the following type signatures: data Foo x = Foo { name :: String , reader :: String -> x } instance Functor Foo where fmap f (Foo n r) = Foo n $ f . r Now I show a natural transformation from Foo to optparse-applicative's Parser…
8
votes
2 answers

Howto create a nested/conditional option with optparse-applicative?

Is possible to create a haskell expression, using the methods in optparse-applicative, that parses program options like this? program [-a [-b]] ... -a and -b are optionals flags (implemented using switch), with the constraint that the -b option…
7
votes
1 answer

How do I create, and distinguish, global options using 'optparse-applicative'?

In my Haskell executable, created using optparse-applicative, I would like to have a global option for --version alongside the global --help option that is available from all subcommands. However the example provided (see below) for adding a…
orome
  • 45,163
  • 57
  • 202
  • 418
7
votes
1 answer

How do I specify names for missing commands in the help message generated by optparse-applicative?

I am attempting to use Hackage's optparse-applicative package and have a question regarding how to specify a certain aspect of the help message displayed when the program is run with insufficient commands specified. The following example program…
mherzl
  • 5,624
  • 6
  • 34
  • 75
6
votes
2 answers

How does optparse-applicative bash autocompletion work?

I'm building a brainfuck compiler. The executable accepts two commands $ brainfuck compile ... and $ brainfuck run. I want the executable to auto complete when pressing tab. E.g. writing $ brainfuck com and then pressing tab should generate $…
The Hoff
  • 904
  • 1
  • 11
  • 22
5
votes
2 answers

Is it possible to have a optparse-applicative option with several parameters?

I just found out that my carefully crafted parser fails to parse any string I throw at it: roi :: Parser (Maybe ROI) roi = optional $ option (ROI <$> auto <*> auto <*> auto <*> auto) $ long "roi" <> metavar "ROI" <> help "Only process…
fho
  • 6,787
  • 26
  • 71
5
votes
1 answer

optparse-applicative: How to handle no-arguments situation in Arrow syntax

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…
cnd
  • 32,616
  • 62
  • 183
  • 313
5
votes
1 answer

optparse-applicative Backtracking

I'm trying to use the optparse-applicative library in an program which should perform a different action depending on the number of arguments. For example, the argument parsing for a program which calculates perimeters: module TestOpts where import…
4
votes
1 answer

(Sub)command synonyms for optparse-applicative

I would like to add synonyms for the subcommands in my Haskell command line tool. For example summarise and summarize should yield the same result. Of course I could just add an entirely separate command summarize, that appears as an own element in…
nevrome
  • 1,471
  • 1
  • 13
  • 28
4
votes
1 answer

How to code for mutually exclusive flags in Options.Applicative

I'm a Haskell newbie. As a learning exercise, I'm trying to port one of my Rust programs to Haskell. In Rust, I use the amazing clap package, and have come across Options.Applicative as a good-looking alternative. Here's an example: import…
Brent.Longborough
  • 9,567
  • 10
  • 42
  • 62
4
votes
1 answer

Parsing "enum" options with optparse-applicative

How do I implement a parser for this example from grep --help: --binary-files=TYPE assume that binary files are TYPE; TYPE is 'binary', 'text', or 'without-match' Assuming that I have data BinaryFiles = Binary | Text |…
nponeccop
  • 13,527
  • 1
  • 44
  • 106
4
votes
2 answers

optparse-applicative: parsing list of pairs

I'm trying to parse a list of pairs with optparse-applicative. Parsing a single pair works, but parsing arbitrarily many using the many combinator fails. import Options.Applicative pairParser = (,) <$> argument str (metavar "s1") …
3
votes
0 answers

How can I rewrite the --help flag output in optparse-applicative

I'm trying to rewrite the automatically generated help output from optparse-applicative. Following code lets me replace the help output: import Options.Applicative import Data.Semigroup ((<>)) data Opts = Opts { optFast :: Bool, optHelp :: Bool…
adius
  • 13,685
  • 7
  • 45
  • 46
3
votes
1 answer

compadd failure during optparse-applicative zsh completion script

So I'm not exactly sure whether this is something wrong with optparse-applicative's script or if I'm using it wrong. In the optparse-applicative readme, it states that programs are made available with automatic completion scripts, with options for…
Anrothan
  • 500
  • 5
  • 13
1
2 3