hledger
Safe HaskellNone
LanguageGHC2021

Hledger.Cli.Conf

Description

Read extra CLI arguments from a hledger config file.

Synopsis

Documentation

data Conf Source #

A hledger config file.

Instances

Instances details
Eq Conf Source # 
Instance details

Defined in Hledger.Cli.Conf

Methods

(==) :: Conf -> Conf -> Bool

(/=) :: Conf -> Conf -> Bool

Show Conf Source # 
Instance details

Defined in Hledger.Cli.Conf

Methods

showsPrec :: Int -> Conf -> ShowS

show :: Conf -> String

showList :: [Conf] -> ShowS

type SectionName = String Source #

The name of a config file section, with surrounding brackets and whitespace removed.

type CommandAlias = String Source #

The name of a command alias (a custom command) defined in a config file.

type CommandLine = String Source #

A command line (a command name followed by arguments), as a single string. Eg the command line which a command alias expands to.

getConf :: RawOpts -> IO (Either String (Conf, Maybe FilePath)) Source #

Try to read a hledger config from a config file specified by --conf, or the first config file found in any of several default file paths. If --no-conf was used, or if no file was specified or found, this returns a null Conf. If a specified file, or the first file found, can not be read or parsed, this returns an error message. Otherwise this returns the parsed Conf, and the file path.

getConf' :: RawOpts -> IO (Conf, Maybe FilePath) Source #

Like getConf but throws an error on failure.

confLookup :: SectionName -> Conf -> [Arg] Source #

Fetch all the arguments/options defined in a section with this name, if it exists. This should be "general" for the unnamed first section, or a hledger command name.

confAliases :: Conf -> [(CommandAlias, CommandLine)] Source #

Get the command aliases (custom commands) defined in this config file, in order of definition. They are defined git-style in an [alias] section, like NAME = CMDLINE; a value may continue on following, more-indented lines. If a name is defined more than once, the last definition should win (callers can rely on the ordering here). An [alias] section line without an = raises a usage error. (In practice it won't, since readConfFile validates with confAliasesE first.)

data ResolvedCommand Source #

The result of resolving a command name that may be a command alias.

Constructors

HledgerCommand String [Arg]

a resolved hledger command name, and arguments to prepend

ShellCommand String

a shell command line (from a !-prefixed alias, ! stripped)

Instances

Instances details
Eq ResolvedCommand Source # 
Instance details

Defined in Hledger.Cli.Conf

Show ResolvedCommand Source # 
Instance details

Defined in Hledger.Cli.Conf

Methods

showsPrec :: Int -> ResolvedCommand -> ShowS

show :: ResolvedCommand -> String

showList :: [ResolvedCommand] -> ShowS

expandCommandAlias :: (String -> Bool) -> [(CommandAlias, CommandLine)] -> String -> ResolvedCommand Source #

Resolve a command name which may be a command alias, to either a real hledger command (with any arguments to prepend) or a shell command line (for a !-prefixed alias). Aliases can refer to other aliases; a name that is an exact builtin command name (per the given predicate), or already seen during this expansion (a self-reference or cycle), stops the recursion. If a name is defined more than once, the first definition in the given list wins (callers wanting the config file's last-definition-wins behaviour should pass reverse (confAliases conf)). This does not enforce the shell-alias trust policy; callers do.

confFileIsTrusted :: RawOpts -> Maybe FilePath -> IO Bool Source #

Is the active config file trusted enough to run its !-prefixed shell command aliases? True if the config file was given explicitly with --conf, or is a user-level config file (~/.hledger.conf or the XDG hledger.conf). False for a config file found automatically in the current directory or a parent (which could come from an untrusted downloaded/shared directory), or when there is no config file.

activeConfFile :: IO (Maybe FilePath) Source #

Get the highest precedence config file, based on the current directory.

activeLocalConfFile :: IO (Maybe FilePath) Source #

Get the highest precedence local config file: a config file in the current directory or above, that is not a user-wide config file.

activeUserConfFile :: IO (Maybe FilePath) Source #

Get the highest precedence user-wide config file, based on the current directory. (This may not be the active config file.)

confFiles :: IO [FilePath] Source #

Get the possibleConfFiles which exist, based on the current directory.

userConfFiles :: IO [FilePath] Source #

Get the possibleUserConfFiles which exist, based on the current directory.

parseConf :: FilePath -> Text -> Either (ParseErrorBundle Text HledgerParseErrorData) [ConfSection] Source #