From 4dc0e359dc55d5c027a324873ea9a7873fca1cdb Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Thu, 22 Aug 2019 17:48:13 -0700 Subject: [PATCH] help: don't require a journal file --- hledger/Hledger/Cli/Main.hs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/hledger/Hledger/Cli/Main.hs b/hledger/Hledger/Cli/Main.hs index 16026c5bc..2160b3b72 100644 --- a/hledger/Hledger/Cli/Main.hs +++ b/hledger/Hledger/Cli/Main.hs @@ -156,6 +156,7 @@ main = do dbgIO "interval from opts" (interval_ $ reportopts_ opts) dbgIO "query from opts & args" (queryFromOpts d $ reportopts_ opts) let + journallesserror = error "journal-less command tried to use the journal" runHledgerCommand -- high priority flags and situations. -h, then --help, then --info are highest priority. | hasHelpFlag argsbeforecmd = dbgIO "" "-h before command, showing general usage" >> printUsage @@ -171,13 +172,15 @@ main = do -- builtin commands | Just (cmdmode, cmdaction) <- findCommand cmd = (case cmd of - "test" -> -- should not read the journal - cmdaction opts (error "journal-less command tried to use the journal") - "add" -> -- should create the journal if missing - (ensureJournalFileExists =<< (head <$> journalFilePathFromOpts opts)) >> - withJournalDo opts (cmdaction opts) - _ -> -- all other commands: read the journal or fail if missing + -- these commands should not require or read the journal + "test" -> cmdaction opts journallesserror + "help" -> cmdaction opts journallesserror + -- this command should create the journal if missing + "add" -> do + (ensureJournalFileExists =<< (head <$> journalFilePathFromOpts opts)) withJournalDo opts (cmdaction opts) + -- other commands read the journal and should fail if it's missing + _ -> withJournalDo opts (cmdaction opts) ) `orShowHelp` cmdmode