mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-10 05:39:31 +03:00
read multiple files: options
This commit is contained in:
parent
77280676d4
commit
2eb4073651
@ -256,7 +256,7 @@ main = do
|
|||||||
|
|
||||||
-- internal commands
|
-- internal commands
|
||||||
| cmd == "activity" = withJournalDo opts histogram `orShowHelp` activitymode
|
| cmd == "activity" = withJournalDo opts histogram `orShowHelp` activitymode
|
||||||
| cmd == "add" = (journalFilePathFromOpts opts >>= ensureJournalFileExists >> withJournalDo opts add) `orShowHelp` addmode
|
| cmd == "add" = (journalFilePathFromOpts opts >>= (ensureJournalFileExists . head) >> withJournalDo opts add) `orShowHelp` addmode
|
||||||
| cmd == "accounts" = withJournalDo opts accounts `orShowHelp` accountsmode
|
| cmd == "accounts" = withJournalDo opts accounts `orShowHelp` accountsmode
|
||||||
| cmd == "balance" = withJournalDo opts balance `orShowHelp` balancemode
|
| cmd == "balance" = withJournalDo opts balance `orShowHelp` balancemode
|
||||||
| cmd == "balancesheet" = withJournalDo opts balancesheet `orShowHelp` balancesheetmode
|
| cmd == "balancesheet" = withJournalDo opts balancesheet `orShowHelp` balancesheetmode
|
||||||
|
@ -250,7 +250,7 @@ s `withAliases` as = s ++ " (" ++ intercalate ", " as ++ ")"
|
|||||||
data CliOpts = CliOpts {
|
data CliOpts = CliOpts {
|
||||||
rawopts_ :: RawOpts
|
rawopts_ :: RawOpts
|
||||||
,command_ :: String
|
,command_ :: String
|
||||||
,file_ :: Maybe FilePath
|
,file_ :: [FilePath]
|
||||||
,rules_file_ :: Maybe FilePath
|
,rules_file_ :: Maybe FilePath
|
||||||
,output_file_ :: Maybe FilePath
|
,output_file_ :: Maybe FilePath
|
||||||
,output_format_ :: Maybe String
|
,output_format_ :: Maybe String
|
||||||
@ -311,7 +311,7 @@ rawOptsToCliOpts rawopts = do
|
|||||||
return defcliopts {
|
return defcliopts {
|
||||||
rawopts_ = rawopts
|
rawopts_ = rawopts
|
||||||
,command_ = stringopt "command" rawopts
|
,command_ = stringopt "command" rawopts
|
||||||
,file_ = maybestringopt "file" rawopts
|
,file_ = map stripquotes $ listofstringopt "file" rawopts
|
||||||
,rules_file_ = maybestringopt "rules-file" rawopts
|
,rules_file_ = maybestringopt "rules-file" rawopts
|
||||||
,output_file_ = maybestringopt "output-file" rawopts
|
,output_file_ = maybestringopt "output-file" rawopts
|
||||||
,output_format_ = maybestringopt "output-format" rawopts
|
,output_format_ = maybestringopt "output-format" rawopts
|
||||||
@ -368,12 +368,14 @@ aliasesFromOpts = map (\a -> fromparse $ runParser accountaliasp () ("--alias "+
|
|||||||
|
|
||||||
-- | Get the (tilde-expanded, absolute) journal file path from
|
-- | Get the (tilde-expanded, absolute) journal file path from
|
||||||
-- 1. options, 2. an environment variable, or 3. the default.
|
-- 1. options, 2. an environment variable, or 3. the default.
|
||||||
journalFilePathFromOpts :: CliOpts -> IO String
|
journalFilePathFromOpts :: CliOpts -> IO [String]
|
||||||
journalFilePathFromOpts opts = do
|
journalFilePathFromOpts opts = do
|
||||||
f <- defaultJournalPath
|
f <- defaultJournalPath
|
||||||
d <- getCurrentDirectory
|
d <- getCurrentDirectory
|
||||||
expandPath d $ fromMaybe f $ file_ opts
|
mapM (expandPath d) $ ifEmpty (file_ opts) [f]
|
||||||
|
where
|
||||||
|
ifEmpty [] d = d
|
||||||
|
ifEmpty l _ = l
|
||||||
|
|
||||||
-- | Get the expanded, absolute output file path from options,
|
-- | Get the expanded, absolute output file path from options,
|
||||||
-- or the default (-, meaning stdout).
|
-- or the default (-, meaning stdout).
|
||||||
|
@ -68,7 +68,7 @@ withJournalDo opts cmd = do
|
|||||||
-- to let the add command work.
|
-- to let the add command work.
|
||||||
rulespath <- rulesFilePathFromOpts opts
|
rulespath <- rulesFilePathFromOpts opts
|
||||||
journalpath <- journalFilePathFromOpts opts
|
journalpath <- journalFilePathFromOpts opts
|
||||||
ej <- readJournalFile Nothing rulespath (not $ ignore_assertions_ opts) journalpath
|
ej <- readJournalFile Nothing rulespath (not $ ignore_assertions_ opts) (head journalpath)
|
||||||
either error' (cmd opts . journalApplyAliases (aliasesFromOpts opts)) ej
|
either error' (cmd opts . journalApplyAliases (aliasesFromOpts opts)) ej
|
||||||
|
|
||||||
-- | Write some output to stdout or to a file selected by --output-file.
|
-- | Write some output to stdout or to a file selected by --output-file.
|
||||||
|
Loading…
Reference in New Issue
Block a user