read multiple files: options

This commit is contained in:
Imuli 2015-05-26 18:15:46 -04:00 committed by Simon Michael
parent 46bbc9e0aa
commit 8385da205e
3 changed files with 9 additions and 7 deletions

View File

@ -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

View File

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

View File

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