From 13a65844404c142f5e05f77240788128cedf95fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Z=C3=A1rybnick=C3=BD?= Date: Tue, 29 Aug 2017 15:18:36 +0200 Subject: [PATCH] ui, web: Enable --pivot and --anon in ui and web (#474) --- hledger-ui/Hledger/UI/Main.hs | 6 +++++- hledger-web/Hledger/Web/Main.hs | 11 +++++++---- hledger/Hledger/Cli/Utils.hs | 2 ++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/hledger-ui/Hledger/UI/Main.hs b/hledger-ui/Hledger/UI/Main.hs index 4327c2b69..bf6c2d78a 100644 --- a/hledger-ui/Hledger/UI/Main.hs +++ b/hledger-ui/Hledger/UI/Main.hs @@ -77,7 +77,11 @@ withJournalDoUICommand uopts@UIOpts{cliopts_=copts} cmd = do rulespath <- rulesFilePathFromOpts copts journalpath <- journalFilePathFromOpts copts ej <- readJournalFiles Nothing rulespath (not $ ignore_assertions_ copts) journalpath - either error' (cmd uopts . journalApplyAliases (aliasesFromOpts copts)) ej + let fn = cmd uopts . + pivotByOpts copts . + anonymiseByOpts copts . + journalApplyAliases (aliasesFromOpts copts) + either error' fn ej runBrickUi :: UIOpts -> Journal -> IO () runBrickUi uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}} j = do diff --git a/hledger-web/Hledger/Web/Main.hs b/hledger-web/Hledger/Web/Main.hs index c6396780d..e121f9c95 100644 --- a/hledger-web/Hledger/Web/Main.hs +++ b/hledger-web/Hledger/Web/Main.hs @@ -51,16 +51,19 @@ runWith opts withJournalDo' opts web withJournalDo' :: WebOpts -> (WebOpts -> Journal -> IO ()) -> IO () -withJournalDo' opts cmd = do - f <- head `fmap` journalFilePathFromOpts (cliopts_ opts) -- XXX head should be safe for now +withJournalDo' opts@WebOpts {cliopts_ = cliopts} cmd = do + f <- head `fmap` journalFilePathFromOpts cliopts -- XXX head should be safe for now -- https://github.com/simonmichael/hledger/issues/202 -- -f- gives [Error#yesod-core] : hGetContents: illegal operation (handle is closed) for some reason -- Also we may be writing to this file. Just disallow it. when (f == "-") $ error' "hledger-web doesn't support -f -, please specify a file path" - readJournalFile Nothing Nothing True f >>= - either error' (cmd opts . journalApplyAliases (aliasesFromOpts $ cliopts_ opts)) + let fn = cmd opts . + pivotByOpts cliopts . + anonymiseByOpts cliopts . + journalApplyAliases (aliasesFromOpts cliopts) + readJournalFile Nothing Nothing True f >>= either error' fn -- | The web command. web :: WebOpts -> Journal -> IO () diff --git a/hledger/Hledger/Cli/Utils.hs b/hledger/Hledger/Cli/Utils.hs index 2f18e7e7c..d1caab891 100644 --- a/hledger/Hledger/Cli/Utils.hs +++ b/hledger/Hledger/Cli/Utils.hs @@ -19,6 +19,8 @@ module Hledger.Cli.Utils writeFileWithBackup, writeFileWithBackupIfChanged, readFileStrictly, + pivotByOpts, + anonymiseByOpts, Test(TestList), ) where