hmt-base-0.20: Haskell Music Theory Base
Safe HaskellSafe-Inferred
LanguageHaskell2010

Music.Theory.Opt

Description

Very simple command line interface option parser.

Only allows options of the form --key=value, with the form --key equal to --key=True.

A list of OptUsr describes the options and provides default values.

get_opt_arg merges user and default values into a table with values for all options.

To fetch options use opt_get and opt_read.

Synopsis

Documentation

type Opt = (String, String) Source #

(Key,Value)

Key does not include leading '--'.

type OptUsr = (String, String, String, String) Source #

(Key,Default-Value,Type,Note)

opt_usr_rw_def :: [Opt] -> [OptUsr] -> [OptUsr] Source #

Re-write default values at OptUsr.

opt_plain :: OptUsr -> Opt Source #

OptUsr to Opt.

opt_usr_help :: OptUsr -> String Source #

OptUsr to help string, indent is two spaces.

opt_get :: [Opt] -> String -> String Source #

Lookup Key in Opt, error if non-existing.

opt_get_nil :: [Opt] -> String -> Maybe String Source #

Variant that returns Nothing if the result is the empty string, else Just the result.

opt_read :: Read t => [Opt] -> String -> t Source #

read of get_opt

opt_param_parse :: String -> Opt Source #

Parse k or k=v string, else error.

opt_parse :: String -> Maybe Opt Source #

Parse option string of form "--opt" or "--key=value".

opt_parse "--opt" == Just ("opt","True")
opt_parse "--key=value" == Just ("key","value")

opt_set_parse :: [String] -> ([Opt], [String]) Source #

Parse option sequence, collating options and non-options.

opt_set_parse (words "--a --b=c d") == ([("a","True"),("b","c")],["d"])

opt_merge :: [Opt] -> [Opt] -> [Opt] Source #

Left-biased Opt merge.

opt_proc :: [OptUsr] -> [String] -> ([Opt], [String]) Source #

Process argument list.

type OptHelp = [String] Source #

Usage text

opt_help_pp :: OptHelp -> [OptUsr] -> String Source #

Format usage pre-amble and opt_help.

opt_usage :: OptHelp -> [OptUsr] -> IO () Source #

Print help and exit.

opt_error :: OptHelp -> [OptUsr] -> t Source #

Print help and error.

opt_verify :: OptHelp -> [OptUsr] -> [Opt] -> IO () Source #

Verify that all Opt have keys that are in OptUsr

opt_get_arg :: Bool -> OptHelp -> [OptUsr] -> IO ([Opt], [String]) Source #

opt_set_parse and maybe opt_verify and opt_merge of getArgs. If arguments include -h or --help run opt_usage

opt_param_set_parse :: String -> [Opt] Source #

Parse param set, one parameter per line.

opt_param_set_parse "a\nb=c" == [("a","True"),("b","c")]

opt_scan :: [String] -> String -> Maybe String Source #

Simple scanner over argument list.

opt_scan_def :: [String] -> (String, String) -> String Source #

Scanner with default value.

opt_scan_read :: Read t => [String] -> (String, t) -> t Source #

Reading scanner with default value.