make --rules-file work again

This commit is contained in:
Simon Michael 2012-03-24 19:53:07 +00:00
parent 70572eb837
commit ed1ea545f5
2 changed files with 12 additions and 2 deletions

View File

@ -124,7 +124,7 @@ generalflags3 = helpflags
fileflags = [
flagReq ["file","f"] (\s opts -> Right $ setopt "file" s opts) "FILE" "use a different journal file; - means stdin"
,flagReq ["rules-file"] (\s opts -> Right $ setopt "rules-file" s opts) "FILE" "conversion rules file for CSV (default: FILE.rules)"
,flagReq ["rules-file"] (\s opts -> Right $ setopt "rules-file" s opts) "RULESFILE" "conversion rules for CSV (default: FILE.rules)"
,flagReq ["alias"] (\s opts -> Right $ setopt "alias" s opts) "ACCT=ALIAS" "display ACCT's name as ALIAS in reports"
]
@ -466,6 +466,16 @@ journalFilePathFromOpts opts = do
then error' $ printf "~ in the journal file path is not supported, please adjust (%s)" f'
else return f'
-- | Get the rules file path from options, if any.
-- If the path contains a literal tilde raise an error to avoid confusion. XXX
rulesFilePathFromOpts :: CliOpts -> Maybe FilePath
rulesFilePathFromOpts opts =
case rules_file_ opts of
Nothing -> Nothing
Just f -> if '~' `elem` f
then error' $ printf "~ in file paths is not supported, please adjust (%s)" f
else Just f
aliasesFromOpts :: CliOpts -> [(AccountName,AccountName)]
aliasesFromOpts = map parseAlias . alias_
where

View File

@ -48,7 +48,7 @@ withJournalDo opts cmd = do
-- We kludgily read the file before parsing to grab the full text, unless
-- it's stdin, or it doesn't exist and we are adding. We read it strictly
-- to let the add command work.
journalFilePathFromOpts opts >>= readJournalFile Nothing Nothing >>=
journalFilePathFromOpts opts >>= readJournalFile Nothing (rulesFilePathFromOpts opts) >>=
either error' (cmd opts . journalApplyAliases (aliasesFromOpts opts))
-- -- | Get a journal from the given string and options, or throw an error.