hledger-0.22.1: The main command-line interface for the hledger accounting tool.

Safe HaskellNone

Hledger.Cli.Options

Contents

Description

Command-line options for the hledger program, and related utilities.

Synopsis

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.

mainmode :: [Name] -> Mode RawOptsSource

The top-level cmdargs mode for hledger.

defCommandMode :: [Name] -> Mode RawOptsSource

A basic subcommand mode with the given command name(s).

helpflags :: [Flag [([Char], [Char])]]Source

Common help flags: --help, --debug, --version...

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.

inRawOpts :: String -> RawOpts -> BoolSource

Is the named option present ?

stringopt :: Eq a => a -> [(a, String)] -> [Char]Source

maybestringopt :: Eq a => a -> [(a, String)] -> Maybe StringSource

listofstringopt :: Eq a => a -> [(a, t)] -> [t]Source

setopt :: t -> [Char] -> [(t, [Char])] -> [(t, [Char])]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.

data CliOpts Source

Command line options. Used in the hledger package and above.

Constructors

CliOpts 

Fields

rawopts_ :: RawOpts
 
command_ :: String
 
file_ :: Maybe FilePath
 
rules_file_ :: Maybe FilePath
 
alias_ :: [String]
 
debug_ :: Int

debug level, set by --debug[=N]. See also debugLevel.

no_new_accounts_ :: Bool
 
width_ :: Maybe String
 
reportopts_ :: ReportOpts
 

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

Constructors

TotalWidth Width

specify the overall width

FieldWidths [Width]

specify each field's width

Instances

data Width Source

A width value.

Constructors

Width Int

set width to exactly this number of characters

Auto

set width automatically from available space

Instances

defaultWidth :: IntSource

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.

tests