optparse-applicative-cmdline-util-0.2.1: Utility functions for working with optparse-applicative
Copyright(c) Tony Zorman 2020 2021 2022
LicenseAGPL
MaintainerTony Zorman <soliditsallgood@mailbox.org>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Options.Applicative.CmdLine.Util

Description

This module contains utility functions for working with the 'optparse-applicative' library.

Much of the module revolves around easily building options that can take "multiple arguments" in the form of separated inputs (e.g. program --option one,two,three,four). This still honours the POSIX standard for options only taking a single argument (by not using spaces to separate the different inputs), while also being very convenient to enter (as opposed to, say, wrapping everything inside quotes).

Another focus involves connecting the attoparsec library with 'optparse-applicative' (this is often useful when options involve more complex parsing patterns).

Synopsis

Types

type AttoParser = Parser Source #

Less confusion as to which Parser one is referring to.

Interfacing with parsing libraries

attoReadM :: AttoParser a -> ReadM a Source #

Attoparsec -- optparse-applicative interface.

optionA :: AttoParser a -> Mod OptionFields a -> Parser a Source #

Like option, but takes an AttoParser instead of a ReadM.

Parsing a list of things

splitWith Source #

Arguments

:: AttoParser p

Parser for a single entry

-> String

Characters that may be used to separate different entries

-> AttoParser [p] 

Parse a collection of things, separated by some specific characters.

splitOn :: String -> AttoParser [Text] Source #

Like splitWith, but the parser is just taking everything it can until the next separation character.

Parsing one thing out of a list of things

anyOf :: [(a, [Text])] -> AttoParser a Source #

Create a parser that matches any of the given a, with the given aliases.

anyOfSkip :: (Char -> Bool) -> [(a, [Text])] -> AttoParser a Source #

Like anyOf but, after having found a match, skip all remaining text as long as the given predicate is true.

anyOfRM :: [(a, [Text])] -> ReadM a Source #

Like anyOf, but return a 'ReadM a' instead of an 'AttoParser a'.

Easier parsing for a thing

aliases :: Foldable t => t Text -> AttoParser Text Source #

Create a parser that matches case-insensitively for all elements of a given list.

Misc

showSepChars :: Foldable t => t Char -> String Source #

Pretty print some container of separation characters, inserting a space between each item.