hsoptions: Haskell library that supports command-line flag processing
Haskell library that supports command-line flag processing.
Too see an user guide and list of features go to https://github.com/josercruz01/hsoptions#table-of-contents.
Flags are declared in the code by using the
make function, which takes the
flag's name, help text and type as arguments.
The flags are parsed from the command line stream of from a file
--usingFile <filename> flag is sent to the program.
Flags can be customized by calling configuration function, such as
aliasIs, that change how the flag behaves, how it
is parsed and validated.
processMain function needs to be called at the beginning of the
function. This function takes as arguments:
A list of
all declared flags
If there is any kind of validation error
called with the list of errors. If the
--help flag was sent by the user
display help is called. Otherwise if there are no problems the
function is called.
A default implementation of
display help is provided in the
defaultDisplayErrors) with a basic bahavior.
success becomes the 'real' main function. It takes as argument
a tuple (
FlagResults is a data structure
that can be used to query flags by using the
just an array of
String containing the remaining not-flag arguments.
A simple example (more in https://github.com/josercruz01/hsoptions/tree/master/examples)
import System.Console.HsOptions userName = make ( "user_name", , "the user name of the app", , [ parser stringParser, , aliasIs ["u"] ] ) userAge = make ("age", "the age of the user", [parser intParser]) flagData = combine [flagToData userName, flagToData userAge] main :: IO () main = processMain "Simple example for HsOptions." flagData success failure defaultDisplayHelp success :: ProcessResults -> IO () success (flags, args) = do let nextAge = (flags `get` userAge) + 5 putStrLn ("Hello " ++ flags `get` userName) putStrLn ("In 5 years you will be " ++ show nextAge ++ " years old!") failure :: [FlagError] -> IO () failure errs = do putStrLn "Some errors occurred:" mapM_ print errs
processMain function each of the input flags is validated against the
declared flags. Within the
success function you can be sure that all required
flags exist, all flag types are correct and all validation was successful.
[Skip to Readme]
|Dependencies||base (==4.6.*), containers (==0.5.*), directory (==1.2.*), hsoptions, parsec (==3.1.*), regex-compat (==0.95.*), regex-posix (==0.95.*) [details]|
|Copyright||(c) Jose Raymundo Cruz (firstname.lastname@example.org)|
|Author||Jose Raymundo Cruz|
|Source repo||head: git clone https://github.com/josercruz01/hsoptions|
|Uploaded||by josercruz01 at Mon Apr 28 18:41:43 UTC 2014|
|Executables||DependentDefaultsDemo, ComplexFlag, SimpleFlag|
|Downloads||523 total (18 in the last 30 days)|
|Rating||(no votes yet) [estimated by rule of succession]|
|Status||Docs uploaded by user
Build status unknown [no reports yet]
Hackage Matrix CI
For package maintainers and hackage trustees