hledger-lib-1.41: A library providing the core functionality of hledger

Safe Haskell | None
Language | Haskell2010

Hledger.Data.RawOptions

Description

hledger's cmdargs modes parse command-line arguments to an intermediate format, RawOpts (an association list), rather than a fixed ADT like CliOpts. This allows the modes and flags to be reused more easily by hledger commands/scripts in this and other packages.

Synopsis

- data RawOpts
- mkRawOpts :: [(String, String)] -> RawOpts
- overRawOpts :: ([(String, String)] -> [(String, String)]) -> RawOpts -> RawOpts
- setopt :: String -> String -> RawOpts -> RawOpts
- setboolopt :: String -> RawOpts -> RawOpts
- unsetboolopt :: String -> RawOpts -> RawOpts
- appendopts :: [(String, String)] -> RawOpts -> RawOpts
- boolopt :: String -> RawOpts -> Bool
- toggleopt :: String -> RawOpts -> Bool
- choiceopt :: (String -> Maybe a) -> RawOpts -> Maybe a
- collectopts :: ((String, String) -> Maybe a) -> RawOpts -> [a]
- stringopt :: String -> RawOpts -> String
- maybestringopt :: String -> RawOpts -> Maybe String
- listofstringopt :: String -> RawOpts -> [String]
- intopt :: String -> RawOpts -> Int
- posintopt :: String -> RawOpts -> Int
- maybeintopt :: String -> RawOpts -> Maybe Int
- maybeposintopt :: String -> RawOpts -> Maybe Int
- maybecharopt :: String -> RawOpts -> Maybe Char
- maybeynopt :: String -> RawOpts -> Maybe Bool
- maybeynaopt :: String -> RawOpts -> Maybe YNA

# Documentation

data RawOpts #

The result of running cmdargs: an association list of option names to string values.

#### Instances

Instances details

Default RawOpts # |
Instance details Defined in Hledger.Data.RawOptions Methods def :: RawOpts #
Show RawOpts # |
Instance details Defined in Hledger.Data.RawOptions Methods showsPrec :: Int -> RawOpts -> ShowS # show :: RawOpts -> String # showList :: [RawOpts] -> ShowS #

mkRawOpts :: [(String, String)] -> RawOpts #

overRawOpts :: ([(String, String)] -> [(String, String)]) -> RawOpts -> RawOpts #

setopt :: String -> String -> RawOpts -> RawOpts #

setboolopt :: String -> RawOpts -> RawOpts #

unsetboolopt :: String -> RawOpts -> RawOpts #

appendopts :: [(String, String)] -> RawOpts -> RawOpts #

boolopt :: String -> RawOpts -> Bool #

Is the named flag present ?

toggleopt :: String -> RawOpts -> Bool #

Like boolopt, except if the flag is repeated on the command line it toggles the value. An even number of repetitions is equivalent to none.

choiceopt #

Arguments

:: (String -> Maybe a) | "parser" that returns `Just` value for valid choice
-> RawOpts | actual options where to look for flag
-> Maybe a | exclusive choice among those returned as `Just` from "parser"

From a list of RawOpts, get the last one (ie the right-most on the command line) for which the given predicate returns a Just value. Useful for exclusive choice flags like --daily|--weekly|--quarterly...

    >>> import Safe (readMay)
    >>> choiceopt Just (RawOpts [("a",""), ("b",""), ("c","")])
    Just "c"
    >>> choiceopt (const Nothing) (RawOpts [("a","")])
    Nothing
    >>> choiceopt readMay (RawOpts [("LT",""),("EQ",""),("Neither","")]) :: Maybe Ordering
    Just EQ

collectopts :: ((String, String) -> Maybe a) -> RawOpts -> [a] #

Collects processed and filtered list of options preserving their order

    >>> collectopts (const Nothing) (RawOpts [("x","")])
    []
    >>> collectopts Just (RawOpts [("a",""),("b","")])
    [("a",""),("b","")]

stringopt :: String -> RawOpts -> String #

maybestringopt :: String -> RawOpts -> Maybe String #

listofstringopt :: String -> RawOpts -> [String] #

intopt :: String -> RawOpts -> Int #

Reads the named option's Int argument. If not present it will return 0. An argument that is too small or too large will raise an error.

posintopt :: String -> RawOpts -> Int #

Reads the named option's natural-number argument. If not present it will return 0. An argument that is negative or too large will raise an error.

maybeintopt :: String -> RawOpts -> Maybe Int #

Reads the named option's Int argument, if it is present. An argument that is too small or too large will raise an error.

maybeposintopt :: String -> RawOpts -> Maybe Int #

Reads the named option's natural-number argument, if it is present. An argument that is negative or too large will raise an error.

maybecharopt :: String -> RawOpts -> Maybe Char #

maybeynopt :: String -> RawOpts -> Maybe Bool #

maybeynaopt :: String -> RawOpts -> Maybe YNA #