Safe Haskell | None |
---|
Common cmdargs modes and flags, a command-line options type, and related utilities used by hledger commands.
- helpflags :: [Flag RawOpts]
- inputflags :: [Flag RawOpts]
- reportflags :: [Flag RawOpts]
- generalflagsgroup1 :: (String, [Flag RawOpts])
- generalflagsgroup2 :: (String, [Flag RawOpts])
- generalflagsgroup3 :: (String, [Flag RawOpts])
- defMode :: Mode RawOpts
- defCommandMode :: [Name] -> Mode RawOpts
- defAddonCommandMode :: Name -> Mode RawOpts
- argsFlag :: FlagHelp -> Arg RawOpts
- showModeHelp :: Mode a -> String
- withAliases :: String -> [String] -> String
- data CliOpts = CliOpts {}
- defcliopts :: CliOpts
- getCliOpts :: Mode RawOpts -> IO CliOpts
- decodeRawOpts :: RawOpts -> RawOpts
- rawOptsToCliOpts :: RawOpts -> IO CliOpts
- checkCliOpts :: CliOpts -> IO CliOpts
- aliasesFromOpts :: CliOpts -> [(AccountName, AccountName)]
- 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
- formatFromOpts :: ReportOpts -> Either String [OutputFormat]
- hledgerAddons :: IO ([String], [String])
- tests_Hledger_Cli_Options :: Test
cmdargs flags & modes
inputflags :: [Flag RawOpts]Source
Common input-related flags: --file, --rules-file, --alias...
reportflags :: [Flag RawOpts]Source
Common report-related flags: --period, --cost, etc.
generalflagsgroup1 :: (String, [Flag RawOpts])Source
generalflagsgroup2 :: (String, [Flag RawOpts])Source
generalflagsgroup3 :: (String, [Flag RawOpts])Source
defCommandMode :: [Name] -> Mode RawOptsSource
A basic subcommand mode with the given command name(s).
defAddonCommandMode :: Name -> Mode RawOptsSource
A basic subcommand mode suitable for an add-on command.
showModeHelp :: Mode a -> StringSource
Get a mode's help message as a nicely wrapped string.
withAliases :: String -> [String] -> StringSource
Add command aliases to the command's help string.
CLI options
Command line options, used in the hledger
package and above.
This is the "opts" used throughout hledger CLI code.
representing the options that arguments that were provided at
startup on the command-line.
CliOpts | |
|
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.
decodeRawOpts :: RawOpts -> RawOptsSource
Convert possibly encoded option values to regular unicode strings.
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.
checkCliOpts :: CliOpts -> IO CliOptsSource
Do final validation of processed opts, raising an error if there is trouble.
CLI option accessors
These do the extra processing required for some options.
aliasesFromOpts :: CliOpts -> [(AccountName, AccountName)]Source
Get the account name aliases from options, if any.
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.
For register:
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.
For balance:
formatFromOpts :: ReportOpts -> Either String [OutputFormat]Source
Parse the format option if provided, possibly returning an error, otherwise get the default value.
Other utils
hledgerAddons :: IO ([String], [String])Source
Get the sorted unique precise names and display names of hledger add-ons found in the current user's PATH. The precise names are the add-on's filename with the hledger- prefix removed. The display names have the file extension removed also, except when it's needed for disambiguation.
- - Also when there are exactly two similar names, one with the .hs or -- .lhs extension and the other with the .exe extension or no -- extension - presumably source and compiled versions of a haskell -- script - we exclude the source version.
This function can return add-on names which shadow built-in command names, but hledger will ignore these.