Safe Haskell | None |
---|
Command-line options for the hledger program, and related utilities.
- mainmode :: [Name] -> Mode RawOpts
- activitymode :: Mode RawOpts
- addmode :: Mode RawOpts
- balancemode :: Mode RawOpts
- balancesheetmode :: Mode RawOpts
- cashflowmode :: Mode RawOpts
- incomestatementmode :: Mode RawOpts
- printmode :: Mode RawOpts
- registermode :: Mode RawOpts
- statsmode :: Mode RawOpts
- testmode :: Mode RawOpts
- convertmode :: Mode RawOpts
- defCommandMode :: [Name] -> Mode RawOpts
- argsFlag :: FlagHelp -> Arg [([Char], [Char])]
- helpflags :: [Flag [([Char], [Char])]]
- inputflags :: [Flag [([Char], [Char])]]
- reportflags :: [Flag [([Char], [Char])]]
- generalflagsgroup1 :: ([Char], [Flag [([Char], [Char])]])
- generalflagsgroup2 :: ([Char], [Flag [([Char], [Char])]])
- generalflagsgroup3 :: ([Char], [Flag [([Char], [Char])]])
- type RawOpts = [(String, String)]
- inRawOpts :: String -> RawOpts -> Bool
- boolopt :: String -> RawOpts -> Bool
- intopt :: String -> RawOpts -> Int
- maybeintopt :: String -> RawOpts -> Maybe Int
- stringopt :: Eq a => a -> [(a, String)] -> [Char]
- maybestringopt :: Eq a => a -> [(a, String)] -> Maybe String
- listofstringopt :: Eq a => a -> [(a, t)] -> [t]
- setopt :: t -> [Char] -> [(t, [Char])] -> [(t, [Char])]
- setboolopt :: t -> [(t, [Char])] -> [(t, [Char])]
- data CliOpts = CliOpts {}
- defcliopts :: CliOpts
- aliasesFromOpts :: CliOpts -> [(AccountName, AccountName)]
- formatFromOpts :: ReportOpts -> Either String [FormatString]
- journalFilePathFromOpts :: CliOpts -> IO String
- rulesFilePathFromOpts :: CliOpts -> IO (Maybe FilePath)
- data OutputWidth
- = TotalWidth Width
- | FieldWidths [Width]
- data Width
- defaultWidth :: Int
- defaultWidthWithFlag :: Int
- widthFromOpts :: CliOpts -> Either String OutputWidth
- getHledgerAddonCommands :: IO [String]
- argsToCliOpts :: [String] -> [String] -> IO CliOpts
- moveFlagsAfterCommand :: [String] -> [String]
- decodeRawOpts :: [(t, SystemString)] -> [(t, String)]
- checkCliOpts :: CliOpts -> IO CliOpts
- rawOptsToCliOpts :: RawOpts -> IO CliOpts
- optserror :: [Char] -> c
- showModeHelp :: Mode a -> String
- debugArgs :: [String] -> CliOpts -> IO ()
- getCliOpts :: Mode RawOpts -> IO CliOpts
- tests_Hledger_Cli_Options :: Test
cmdargs modes & flags
These tell cmdargs how to parse the command line arguments. There's one mode for each internal subcommand, plus a main mode.
defCommandMode :: [Name] -> Mode RawOptsSource
A basic subcommand mode with the given command name(s).
inputflags :: [Flag [([Char], [Char])]]Source
Common input-related flags: --file, --rules-file, --alias...
reportflags :: [Flag [([Char], [Char])]]Source
Common report-related flags: --period, --cost, --display etc.
raw options
To allow the cmdargs modes to be reused and extended by other packages (eg, add-ons which want to mimic the standard hledger options), we parse the command-line arguments to a simple association list, not a fixed ADT.
type RawOpts = [(String, String)]Source
Our cmdargs modes parse arguments into an association list for better reuse.
listofstringopt :: Eq a => a -> [(a, t)] -> [t]Source
setboolopt :: t -> [(t, [Char])] -> [(t, [Char])]Source
CLI options
Raw options are converted to a more convenient, package-specific options structure. This is the "opts" used throughout hledger CLI code.
Command line options. Used in the hledger
package and above.
CliOpts | |
|
CLI option accessors
Some options require more processing. Possibly these should be merged into argsToCliOpts.
aliasesFromOpts :: CliOpts -> [(AccountName, AccountName)]Source
Get the account name aliases from options, if any.
formatFromOpts :: ReportOpts -> Either String [FormatString]Source
Parse the format option if provided, possibly returning an error, otherwise get the default value.
journalFilePathFromOpts :: CliOpts -> IO StringSource
Get the (tilde-expanded, absolute) journal file path from 1. options, 2. an environment variable, or 3. the default.
rulesFilePathFromOpts :: CliOpts -> IO (Maybe FilePath)Source
Get the (tilde-expanded) rules file path from options, if any.
data OutputWidth Source
Output width configuration (for register).
TotalWidth Width | specify the overall width |
FieldWidths [Width] | specify each field's width |
A width value.
Default width of hledger console output.
defaultWidthWithFlag :: IntSource
Width of hledger console output when the -w flag is used with no value.
widthFromOpts :: CliOpts -> Either String OutputWidthSource
Parse the width option if provided, possibly returning an error, otherwise get the default value.
utilities
getHledgerAddonCommands :: IO [String]Source
Get the unique suffixes (without hledger-) of hledger-* executables found in the current user's PATH, or the empty list if there is any problem.
argsToCliOpts :: [String] -> [String] -> IO CliOptsSource
Parse hledger CLI options from these command line arguments and add-on command names, or raise any error.
moveFlagsAfterCommand :: [String] -> [String]Source
A hacky workaround for cmdargs not accepting flags before the subcommand name: try to detect and move such flags after the command. This allows the user to put them in either position. The order of options is not preserved, but this should be ok.
Since we're not parsing flags as precisely as cmdargs here, this is imperfect. We make a decent effort to: - move all no-argument help and input flags - move all required-argument help and input flags along with their values, space-separated or not - not confuse things further or cause misleading errors.
decodeRawOpts :: [(t, SystemString)] -> [(t, String)]Source
Convert possibly encoded option values to regular unicode strings.
checkCliOpts :: CliOpts -> IO CliOptsSource
Do final validation of processed opts, raising an error if there is trouble.
rawOptsToCliOpts :: RawOpts -> IO CliOptsSource
Parse raw option string values to the desired final data types. Any relative smart dates will be converted to fixed dates based on today's date. Parsing failures will raise an error.
optserror :: [Char] -> cSource
Raise an error, showing the specified message plus a hint about --help.
showModeHelp :: Mode a -> StringSource
Get a mode's help message as a nicely wrapped string.
debugArgs :: [String] -> CliOpts -> IO ()Source
Print debug info about arguments and options if --debug is present.
getCliOpts :: Mode RawOpts -> IO CliOptsSource
Parse hledger CLI options from the command line using the given cmdargs mode, and either return them or, if a help flag is present, print the mode help and exit the program.