Safe Haskell | Safe-Inferred |
---|
- data Arg a
- data OptInfo
- data PosInfo
- optInfo :: [String] -> OptInfo
- posInfo :: PosInfo
- flag :: OptInfo -> Arg Bool
- flagAll :: OptInfo -> Arg [Bool]
- vFlag :: a -> [(a, OptInfo)] -> Arg a
- vFlagAll :: [a] -> [(a, OptInfo)] -> Arg [a]
- opt :: ArgVal a => a -> OptInfo -> Arg a
- defaultOpt :: ArgVal a => a -> a -> OptInfo -> Arg a
- optAll :: (ArgVal a, Ord a) => [a] -> OptInfo -> Arg [a]
- defaultOptAll :: (ArgVal a, Ord a) => a -> [a] -> OptInfo -> Arg [a]
- pos :: ArgVal a => Int -> a -> PosInfo -> Arg a
- revPos :: ArgVal a => Int -> a -> PosInfo -> Arg a
- posAny :: ArgVal a => [a] -> PosInfo -> Arg [a]
- posLeft :: ArgVal a => Int -> [a] -> PosInfo -> Arg [a]
- posRight :: ArgVal a => Int -> [a] -> PosInfo -> Arg [a]
- revPosLeft :: ArgVal a => Int -> [a] -> PosInfo -> Arg [a]
- revPosRight :: ArgVal a => Int -> [a] -> PosInfo -> Arg [a]
- value :: Arg a -> Term a
- required :: Arg (Maybe a) -> Term a
- nonEmpty :: Arg [a] -> Term [a]
- lastOf :: Arg [a] -> Term a
Documentation
Argument Information
Information about an optional argument. Exposes the folowing fields.
optName
- :: String: defaults to
""
. optDoc
- :: String: defaults to
""
. optSec
- :: String: defaults to
"OPTIONS"
.
Information about a positional argument. Exposes the folowing fields.
posName
- :: String: defaults to
""
. posDoc
- :: String: defaults to
""
. posSec
- :: String: defautts to
"ARGUMENTS"
.
optInfo :: [String] -> OptInfoSource
Initialize an OptInfo
by providing a list of names. The fields
optName
, optDoc
, and optSec
can then be manipulated post-mortem,
as in
inf =(optInfo [ "i", "insufflation" ]) { optName = "INSUFFERABLE" , optDoc = "in the haunted house's harrow" , optSec = "NOT FOR AUGHT" }
Names of one character in length will be prefixed by -
on the command line,
while longer names will be prefixed by --
.
It is considered a programming error to provide an empty list of names to optInfo.
Initialize a PosInfo
. The fields posName
, posDoc
, and posSec
can then be manipulated post-mortem, as in
inf = posInfo { posName = "DEST" , posDoc = "A destination for the operation." , posSec = "DESTINATIONS" }
The fields posName
and posDoc
must be non-empty strings for the argument
to be listed with its documentation under the section posSec
of generated
help.
Optional arguments
An optional argument is specified on the command line by a name possibly followed by a value.
The name of an option can be short or long.
- A short name is a dash followed by a single alphanumeric character:
-h
,-q
,-I
. - A long name is two dashes followed by alphanumeric characters and dashes:
--help
,--silent
,--ignore-case
.
More than one name may refer to the same optional argument. For example in
a given program the names -q
, --quiet
, and --silent
may all stand for
the same boolean argument indicating the program to be quiet. Long names can
be specified by any non-ambiguous prefix.
There are three ways to assign values to an optional argument on the command line.
- As the next token on the command line:
-o a.out
,--output a.out
. - Glued to a short name:
-oa.out
. - Glued to a long name after an equal character:
--output=a.out
.
Glued forms are necessary if the value itself starts with a dash, as is the
case for negative numbers, --min=-10
.
Flag options
flag :: OptInfo -> Arg BoolSource
Create a command line flag that can appear at most once on the
command line. Yields False
in absence and True
in presence.
flagAll :: OptInfo -> Arg [Bool]Source
As flag
but may appear an infinity of times. Yields a list of True
s
as long as the number of times present.
vFlag :: a -> [(a, OptInfo)] -> Arg aSource
vFlag
v [ ( v1, ai1 ), ... ]
is an argument that can be present at most
once on the command line. It takes on the value vn
when appearing as
ain
.
Assignable options
opt :: ArgVal a => a -> OptInfo -> Arg aSource
opt
v ai
is an optional argument that yields v
in absence, or an
assigned value in presence. If the option is present, but no value is
assigned, it is considered a user-error and usage is printed on exit.
defaultOpt :: ArgVal a => a -> a -> OptInfo -> Arg aSource
defaultOpt
def v ai
is as opt
except if it is present and no value is
assigned on the command line, def
is the result.
defaultOptAll :: (ArgVal a, Ord a) => a -> [a] -> OptInfo -> Arg [a]Source
defaultOptAll
def vs ai
is like optAll
except that if it is present
without being assigned a value, the value def
takes its place in the list
of results.
Positional arguments
Positional arguments are tokens on the command line that are not option names or the values being assigned to an optional argument.
Since positional arguments may be mistaken as the optional value of an
optional argument or they may need to look like an optional name, anything
that follows the special token --
(with spaces on both sides) on the command
line is considered to be a positional argument.
Positional arguments are listed in documentation sections iff they are
assigned both an argName
and an argDoc
.
pos :: ArgVal a => Int -> a -> PosInfo -> Arg aSource
pos
n v ai
is an argument defined by the n
th positional argument
on the command line. If absent the value v
is returned.
posAny :: ArgVal a => [a] -> PosInfo -> Arg [a]Source
posAny
vs ai
yields a list of all positional arguments or vs
if none
are present.
posLeft :: ArgVal a => Int -> [a] -> PosInfo -> Arg [a]Source
posLeft
n vs ai
yield a list of all positional arguments to the left of
the n
th positional argument or vs
if there are none.
revPosLeft :: ArgVal a => Int -> [a] -> PosInfo -> Arg [a]Source
revPosLeft
n vs ai
is as posLeft
except n
counts from the end of the
command line to the front.
revPosRight :: ArgVal a => Int -> [a] -> PosInfo -> Arg [a]Source
revPosRight
n vs ai
is as posRight
except n
counts from the end of
the command line to the front.
Arguments as Terms
required :: Arg (Maybe a) -> Term aSource
required
arg
converts arg
into a Term
such that it fails in the
Nothing
and yields a
in the Just
.
This is used for required positional arguments. There is nothing stopping you from using it with optional arguments, except that they would no longer be optional and it would be confusing from a user's perspective.