/
Applicative.hs
235 lines (208 loc) · 5.77 KB
/
Applicative.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
module Options.Applicative (
-- * Applicative option parsers
--
-- | This module exports all one should need for defining and using
-- optparse-applicative command line option parsers.
--
-- See <https://github.com/pcapriotti/optparse-applicative> for a tutorial,
-- and a general introduction to applicative option parsers.
--
-- See the sections below for more detail
-- * Exported modules
--
-- | The standard @Applicative@ module is re-exported here for convenience.
module Control.Applicative,
-- * Option Parsers
--
-- | A 'Parser' is the core type in optparse-applicative. A value of type
-- @Parser a@ represents a specification for a set of options, which will
-- yield a value of type a when the command line arguments are successfully
-- parsed.
--
-- There are several types of primitive 'Parser'.
--
-- * Flags: simple no-argument options. When a flag is encountered on the
-- command line, its value is returned.
--
-- * Options: options with an argument. An option can define a /reader/,
-- which converts its argument from String to the desired value, or throws a
-- parse error if the argument does not validate correctly.
--
-- * Arguments: positional arguments, validated in the same way as option
-- arguments.
--
-- * Commands. A command defines a completely independent sub-parser. When a
-- command is encountered, the whole command line is passed to the
-- corresponding parser.
--
-- See the "Parser Builders" section for how to construct and customise
-- these parsers.
Parser,
-- ** Parser builders
--
-- | This section contains utility functions and combinators to create parsers
-- for individual options.
--
-- Each parser builder takes an option modifier. A modifier can be created by
-- composing the basic modifiers provided by here using the 'Monoid' operations
-- 'mempty' and 'mappend', or their aliases 'idm' and '<>'.
--
-- For example:
--
-- > out = strOption
-- > ( long "output"
-- > <> short 'o'
-- > <> metavar "FILENAME" )
--
-- creates a parser for an option called \"output\".
flag,
flag',
switch,
strOption,
option,
strArgument,
argument,
subparser,
hsubparser,
abortOption,
infoOption,
helper,
-- ** Modifiers
--
-- | 'Parser' builders take a modifier, which represents a modification of the
-- properties of an option, and can be composed as a monoid.
--
-- Contraints are often used to ensure that the modifiers can be sensibly applied.
-- For example, positional arguments can't be specified by long or short names,
-- so the 'HasName' constraint is used to ensure we have a flag or option.
Mod,
short,
long,
help,
helpDoc,
value,
showDefaultWith,
showDefault,
metavar,
noArgError,
hidden,
internal,
style,
command,
commandGroup,
completeWith,
action,
completer,
idm,
mappend,
OptionFields,
FlagFields,
ArgumentFields,
CommandFields,
HasName,
HasCompleter,
HasValue,
HasMetavar,
-- ** Readers
--
-- | A reader is used by the 'option' and 'argument' builders to parse
-- the data passed by the user on the command line into a data type.
--
-- The most common are 'str' which is used for 'String' like types,
-- including 'ByteString' and 'Text'; and 'auto', which uses the 'Read'
-- typeclass, and is good for simple types like 'Int' or 'Double'.
--
-- More complex types can use the 'eitherReader' or 'maybeReader'
-- functions to pattern match or use a more expressive parser like a
-- member of the 'Parsec' family.
ReadM,
auto,
str,
maybeReader,
eitherReader,
disabled,
readerAbort,
readerError,
-- * Program descriptions
--
-- ** 'ParserInfo'
--
-- | A 'ParserInfo' describes a command line program, used to generate a help
-- screen. Two help modes are supported: brief and full. In brief mode, only
-- an option and argument summary is displayed, while in full mode each
-- available option and command, including hidden ones, is described.
--
-- A 'ParserInfo' should be created with the 'info' function and a set of
-- 'InfoMod' modifiers.
--
info,
ParserInfo(..),
InfoMod,
fullDesc,
briefDesc,
header,
headerDoc,
footer,
footerDoc,
progDesc,
progDescDoc,
failureCode,
noIntersperse,
forwardOptions,
-- * Running parsers
--
-- | The execParser family of functions are used to run parsers
execParser,
customExecParser,
execParserPure,
-- ** Handling parser results manually
getParseResult,
handleParseResult,
parserFailure,
renderFailure,
overFailure,
-- ** 'ParserPrefs'
--
-- | A 'ParserPrefs' contains general preferences for all command-line
-- options, and should be built with the 'prefs' function.
prefs,
ParserPrefs(..),
PrefsMod,
multiSuffix,
disambiguate,
showHelpOnError,
showHelpOnEmpty,
noBacktrack,
columns,
defaultPrefs,
-- * Completions
--
-- | optparse-applicative supplies a rich completion system for bash,
-- zsh, and fish shells.
--
-- 'Completer' functions are used for option and argument to complete
-- their values.
--
-- Use the 'completer' builder to use these.
-- The 'action' and 'completeWith' builders are also provided for
-- convenience, to use 'bashCompleter' and 'listCompleter' as a 'Mod'.
Completer,
mkCompleter,
listIOCompleter,
listCompleter,
bashCompleter,
-- * Types
ParseError(..),
ParserHelp(..),
ParserFailure(..),
ParserResult(..),
CompletionResult(..)
) where
-- reexport Applicative here for convenience
import Control.Applicative
import Options.Applicative.Common
import Options.Applicative.Builder
import Options.Applicative.Builder.Completer
import Options.Applicative.Extra
import Options.Applicative.Types
{-# ANN module "HLint: ignore Use import/export shortcut" #-}