From 2eb40736519d80ad21ea9118eba0f76ded94c356 Mon Sep 17 00:00:00 2001 From: Imuli Date: Tue, 26 May 2015 18:15:46 -0400 Subject: [PATCH] read multiple files: options --- hledger/Hledger/Cli/Main.hs | 2 +- hledger/Hledger/Cli/Options.hs | 12 +++++++----- hledger/Hledger/Cli/Utils.hs | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/hledger/Hledger/Cli/Main.hs b/hledger/Hledger/Cli/Main.hs index 0bb0eee2e..b3667f0b7 100644 --- a/hledger/Hledger/Cli/Main.hs +++ b/hledger/Hledger/Cli/Main.hs @@ -256,7 +256,7 @@ main = do -- internal commands | 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 == "balance" = withJournalDo opts balance `orShowHelp` balancemode | cmd == "balancesheet" = withJournalDo opts balancesheet `orShowHelp` balancesheetmode diff --git a/hledger/Hledger/Cli/Options.hs b/hledger/Hledger/Cli/Options.hs index 9f121c15c..d514e4606 100644 --- a/hledger/Hledger/Cli/Options.hs +++ b/hledger/Hledger/Cli/Options.hs @@ -250,7 +250,7 @@ s `withAliases` as = s ++ " (" ++ intercalate ", " as ++ ")" data CliOpts = CliOpts { rawopts_ :: RawOpts ,command_ :: String - ,file_ :: Maybe FilePath + ,file_ :: [FilePath] ,rules_file_ :: Maybe FilePath ,output_file_ :: Maybe FilePath ,output_format_ :: Maybe String @@ -311,7 +311,7 @@ rawOptsToCliOpts rawopts = do return defcliopts { rawopts_ = rawopts ,command_ = stringopt "command" rawopts - ,file_ = maybestringopt "file" rawopts + ,file_ = map stripquotes $ listofstringopt "file" rawopts ,rules_file_ = maybestringopt "rules-file" rawopts ,output_file_ = maybestringopt "output-file" 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 -- 1. options, 2. an environment variable, or 3. the default. -journalFilePathFromOpts :: CliOpts -> IO String +journalFilePathFromOpts :: CliOpts -> IO [String] journalFilePathFromOpts opts = do f <- defaultJournalPath 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, -- or the default (-, meaning stdout). diff --git a/hledger/Hledger/Cli/Utils.hs b/hledger/Hledger/Cli/Utils.hs index 735050e9d..d70152263 100644 --- a/hledger/Hledger/Cli/Utils.hs +++ b/hledger/Hledger/Cli/Utils.hs @@ -68,7 +68,7 @@ withJournalDo opts cmd = do -- to let the add command work. rulespath <- rulesFilePathFromOpts 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 -- | Write some output to stdout or to a file selected by --output-file.