From ed1ea545f5c7b82cf94cbf4bef1f0957aaaf5e1c Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sat, 24 Mar 2012 19:53:07 +0000 Subject: [PATCH] make --rules-file work again --- hledger/Hledger/Cli/Options.hs | 12 +++++++++++- hledger/Hledger/Cli/Utils.hs | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/hledger/Hledger/Cli/Options.hs b/hledger/Hledger/Cli/Options.hs index 9a00b09f3..2de7fe11c 100644 --- a/hledger/Hledger/Cli/Options.hs +++ b/hledger/Hledger/Cli/Options.hs @@ -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 diff --git a/hledger/Hledger/Cli/Utils.hs b/hledger/Hledger/Cli/Utils.hs index 8e3b0540b..f5c9321ed 100644 --- a/hledger/Hledger/Cli/Utils.hs +++ b/hledger/Hledger/Cli/Utils.hs @@ -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.