Questions tagged [optparse-applicative]

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

optparse-applicative

`

37 questions
3
votes
1 answer

Programming pattern or library (i.e. idiomatic way) to handle CLI arguments semantic errors?

I have a Haskell application which uses optparse-applicative library for CLI arguments parsing. My data type for CLI arguments contains FilePaths (both files and directories), Doubles and etc. optparse-applicative can handle parse errors but I want…
Shersh
  • 9,019
  • 3
  • 33
  • 61
3
votes
1 answer

How to use options with multiple values with Haskell's optparse-applicative

I have the following Haskell code using optparse-applicative which hangs at runtime. main :: IO () main = do printf "Start...\n" args <- execParser $ info args fullDesc printf "Cmdline args: %s\n" (show args) args :: Parser [Integer] args =…
vidi
  • 2,056
  • 16
  • 34
3
votes
1 answer

handle exception from openFile in a optparse-applicative ReadM

Using optparse-applicative, I'd like to have an optional argument, which should be a path to a file, or when not specified, stdin. The obvious choice here is to make this argument type IO Handle and when an argument is passed in use openFile. Here's…
Bailey Parker
  • 15,599
  • 5
  • 53
  • 91
2
votes
0 answers

Is there a way to get the usage block of optparse-aplicative parser outside the IO monad

optparse-applicative package provides very powerful tools for command-line arguments parsing. Among them is the automatic usage text generation, which is printed in case of parsing error or by --help option if the parser is used by execParser…
2
votes
2 answers

optparse-applicative with custom monad

I'm trying to use my own monad (instead of IO) with customExecParser https://hackage.haskell.org/package/optparse-applicative-0.15.1.0/docs/Options-Applicative-Extra.html#v:customExecParser. So I've ended up with (significant function being…
Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286
2
votes
1 answer

Parsing user options into custom data types with OptParse-Applicative

I'm trying to build a CLI food journal app. And this is the data type I want the user input to be parsed in. data JournalCommand = JournalSearch Query DataTypes Ingridents BrandOwnder PageNumber | JournalReport Query DataTypes Ingridents…
distro.obs
  • 181
  • 9
2
votes
2 answers

optparse-applicative subcommand help text

I'm using optparse-applicative that comes with stackage lts 5.1 I have a parser with subcommands and I have described a help text for their options, but they don't show. This is the output when I run the executable with --help : [david@devcentos65…
2
votes
0 answers

program mode determined from arguments count [optparse-applicative]

i will determine the program mode from the arguments count (without flags / 'subparser' & 'command') but without success. ghci session main% stack ghci optparse-applicative Configuring GHCi with the following packages: GHCi, version 7.10.2:…
j-keck
  • 1,021
  • 1
  • 7
  • 13
1
vote
1 answer

Optparse-applicative: consecutive parsing (ReadM)

I have a basic command add that takes 2 kind of arguments: a word or a tag. A tag is just a word starting by +. A word is just a String. It can contain at least one argument (I use some for this). data Arg = Add AddOpts data AddOpts = AddOpts {…
soywod
  • 4,377
  • 3
  • 26
  • 47
1
vote
1 answer

subcommand help using optparse applicative

I am having two issues with optparse-applicative: (I put the issues together, since it is likely there is one underlying mis-conception). It is saying that the usage is : (COMMAND | COMMAND) crime cli - process CRIME template and deploy…
Dr.YSG
  • 7,171
  • 22
  • 81
  • 139
1
vote
1 answer

Parsing CLI options for a product type

I want to parse command line options corresponding to a product type resembling below. data SumType1 = d | e | f data SumType2 = g | h | i data Config = Config { a :: Bool, b :: SumType1, c :: SumType2 } pB :: Parser SumType1 pB =…
Sanchayan Maity
  • 637
  • 6
  • 19
1
vote
1 answer

Generate command line strings using optparse-applicative

Given a Parser a and a value of type a is it possible to generate the relevant command-line (in textual format)? (Basically, the exact reverse of what optparse-applicative is generally used for!) For example, given something like... data Args =…
Saurabh Nanda
  • 6,373
  • 5
  • 31
  • 60
1
vote
1 answer

Error: "Variable not in scope: (<>)" with the library optparse-applicative

I was watching a video made by Richard Cook on SafariBookOnline. He builds a command line app with Haskell. In this video, he explains some basic concepts while writing a program to parse command lines arguments. I am quite new to Haskell, and I…
Alex k
  • 13
  • 3
1
vote
2 answers

Option.Applicative: How to parse a combined parser with a flag?

I have complicated command line options, as data Arguments = Arguments Bool (Maybe SubArguments) data SubArguments = SubArguments String String I want to parse these subarguments with a flag: programName --someflag --subarguments "a"…
Pieter
  • 777
  • 5
  • 17
0
votes
1 answer

Perform checks that include multiple options

I have type Month = Int parseMonths :: OP.Parser (Month, Month) parseMonths = liftA2 (,) (OP.option (OP.eitherReader $ parseNumber "month" (\n -> 1<=n && n<=12) "month") (OP.metavar "MONTH" <> …
Lemming
  • 577
  • 6
  • 16