HORIZON HASKELLDocslts/ghc-10.0.x8c2f8e82026-10-19Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8c2f8e8 · 2026-10-19

Modulehledger-lib-1.52.4GHC2021

Hledger.Data.RawOptions

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.

  • 1 type
  • 21 values
  • Packagehledger-lib-1.52.4
  • Exports22
  • LanguageGHC2021
  • LicenceGPL-3.0-or-later
  • SourceRawOptions.hs
newtypenewtype RawOpts
#

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

Instances2Show, Default
  • Show RawOptsDefined in hledger-lib-1.52.4 · Hledger.Data.RawOptions
  • Default RawOptsDefined in hledger-lib-1.52.4 · Hledger.Data.RawOptions
valuetoggleopt :: 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.

valuechoiceopt
  1. :: (String -> Maybe a)

    "parser" that returns Just value for valid choice

  2. -> RawOpts

    actual options where to look for flag

  3. -> 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...

Example4 expressions
import Safe (readMay)choiceopt Just (RawOpts [("a",""), ("b",""), ("c","")])Just "c"choiceopt (const Nothing) (RawOpts [("a","")])Nothingchoiceopt readMay (RawOpts [("LT",""),("EQ",""),("Neither","")]) :: Maybe OrderingJust EQ
valuecollectopts :: ((String, String) -> Maybe a) -> RawOpts -> [a]
#

Collects processed and filtered list of options preserving their order

Example2 expressions
collectopts (const Nothing) (RawOpts [("x","")])[]collectopts Just (RawOpts [("a",""),("b","")])[("a",""),("b","")]
valueintopt :: 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.

valueposintopt :: 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.

valuemaybeintopt :: 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.

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