p package:optparse-applicative
Generate a
ParserFailure from a
ParseError in a given
Context.
This function can be used, for example, to show the help text for a
parser:
handleParseResult . Failure $ parserFailure pprefs pinfo (ShowHelpText Nothing) mempty
Group options together under a common heading in the help text.
For example, if we have:
Args
<$> parseMain
<*> parserOptionGroup "Group A" parseA
<*> parserOptionGroup "Group B" parseB
<*> parseOther
Then the help page will look like:
Available options:
<main options>
<other options>
Group A
<A options>
Group B
<B options>
backtrack to parent parser when a subcommand fails (default:
Backtrack)
Width at which to hang the brief description
number of columns in the terminal, used to format the help page
(default: 80)
automatically disambiguate abbreviations (default: False)
when displaying long names in usage and help, use an '=' sign for long
names, rather than a single space (default: False)
when displaying subparsers' usage help, show parent options under a
"global options" section (default: False)
metavar suffix for multiple options
show the help text for a command or subcommand if it fails with no
input (default: False)
always show help text on parse errors (default: False)
Indentation width for tables
Specify a short program description.
Specify a short program description as a 'Prettyprinter.Doc AnsiStyle'
value.
Convert a paragraph into a
Chunk. The resulting chunk is
composed by the words of the original paragraph separated by
softlines, so it will be automatically word-wrapped when rendering the
underlying document.
This satisfies:
isEmpty . paragraph = null . words
Generate the help text for a program.
Layout a document depending on the page width, if one has been
specified.
>>> let prettyPageWidth (AvailablePerLine l r) = "Width:" <+> pretty l <> ", ribbon fraction:" <+> pretty r
>>> let doc = "prefix" <+> pageWidth (brackets . prettyPageWidth)
>>> putDocW 32 (vsep [indent n doc | n <- [0,4,8]])
prefix [Width: 32, ribbon fraction: 1.0]
prefix [Width: 32, ribbon fraction: 1.0]
prefix [Width: 32, ribbon fraction: 1.0]
(plural n one many) is
one if
n is
1, and
many otherwise. A typical use case is adding
a plural "s".
>>> let things = [True]
>>> let amount = length things
>>> pretty things <+> "has" <+> pretty amount <+> plural "entry" "entries" amount
[True] has 1 entry
>>> pretty 1 <+> pretty "hello" <+> pretty 1.234
1 hello 1.234