Copyright | (c) Simon Bergot |
---|---|
License | BSD3 |
Maintainer | simon.bergot@gmail.com |
Stability | unstable |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell98 |
Collection of functions which are basically shortcuts of System.Console.EasyConsole.Params versions. If you cannot find a parameter fitting your needs, you should check this module.
Values provided to parsedBy
and andBy
should be created with
the following functions. The types are inferred. ArgParser will use
readMaybe
to convert the arguments to haskell values, except for strings
which will be passed unmodified.
Flags can be passed in long form (--foo
) or short form (-f
)
You may also provide a prefix form such as --fo
.
Mandatory parameters will fail if the argument is absent or invalid.
Optional parameters only fail if the argument is invalid (ie foo
passed
as Int
)
Note that single arg parameters need exactly one arg, and that multiple args parameters can have any number of args (0 included).
- boolFlag :: Key -> FlagParam Bool
- reqFlag :: RawRead a => Key -> StdArgParam a
- optFlag :: RawRead a => a -> Key -> StdArgParam a
- reqPos :: RawRead a => Key -> StdArgParam a
- optPos :: RawRead a => a -> Key -> StdArgParam a
- reqFlagArgs :: RawRead a => Key -> b -> (b -> a -> b) -> StdArgParam b
- optFlagArgs :: RawRead a => b -> Key -> b -> (b -> a -> b) -> StdArgParam b
- posArgs :: RawRead a => Key -> b -> (b -> a -> b) -> StdArgParam b
- class RawRead a
Parameters without args
A simple command line flag.
The parsing function will return True
if the flag is present, if the flag is provided to
the command line, and False otherwise.
For a key foo
, the flag can either be --foo
or -f
Parameters with one arg
Flags
:: RawRead a | |
=> a | Default value |
-> Key | Flag name |
-> StdArgParam a |
An optional flag argument parameter
Positional
:: RawRead a | |
=> Key | Param name |
-> StdArgParam a |
A mandatory positional argument parameter
:: RawRead a | |
=> a | Default value |
-> Key | Param name |
-> StdArgParam a |
An optional positional argument parameter
Parameters with multiple args
Flags
:: RawRead a | |
=> Key | Flag name |
-> b | Initial value |
-> (b -> a -> b) | Accumulation function |
-> StdArgParam b |
A mandatory flag argument parameter taking multiple arguments
:: RawRead a | |
=> b | Default value |
-> Key | Flag name |
-> b | Initial value |
-> (b -> a -> b) | Accumulation function |
-> StdArgParam b |
An optional flag argument parameter taking multiple arguments
Positionnal
:: RawRead a | |
=> Key | Param name |
-> b | Initial value |
-> (b -> a -> b) | Accumulation function |
-> StdArgParam b |
A parameter consuming all the remaining positional parameters