help: don't require a journal file
This commit is contained in:
		
							parent
							
								
									9f8c24fe71
								
							
						
					
					
						commit
						4dc0e359dc
					
				| @ -156,6 +156,7 @@ main = do | |||||||
|   dbgIO "interval from opts" (interval_ $ reportopts_ opts) |   dbgIO "interval from opts" (interval_ $ reportopts_ opts) | ||||||
|   dbgIO "query from opts & args" (queryFromOpts d $ reportopts_ opts) |   dbgIO "query from opts & args" (queryFromOpts d $ reportopts_ opts) | ||||||
|   let |   let | ||||||
|  |     journallesserror = error "journal-less command tried to use the journal" | ||||||
|     runHledgerCommand |     runHledgerCommand | ||||||
|       -- high priority flags and situations. -h, then --help, then --info are highest priority. |       -- high priority flags and situations. -h, then --help, then --info are highest priority. | ||||||
|       | hasHelpFlag argsbeforecmd = dbgIO "" "-h before command, showing general usage" >> printUsage |       | hasHelpFlag argsbeforecmd = dbgIO "" "-h before command, showing general usage" >> printUsage | ||||||
| @ -171,13 +172,15 @@ main = do | |||||||
|       -- builtin commands |       -- builtin commands | ||||||
|       | Just (cmdmode, cmdaction) <- findCommand cmd = |       | Just (cmdmode, cmdaction) <- findCommand cmd = | ||||||
|         (case cmd of |         (case cmd of | ||||||
|           "test" -> -- should not read the journal |            -- these commands should not require or read the journal | ||||||
|             cmdaction opts (error "journal-less command tried to use the journal") |           "test" -> cmdaction opts journallesserror | ||||||
|           "add" ->  -- should create the journal if missing |           "help" -> cmdaction opts journallesserror | ||||||
|             (ensureJournalFileExists =<< (head <$> journalFilePathFromOpts opts)) >> |           -- this command should create the journal if missing | ||||||
|             withJournalDo opts (cmdaction opts) |           "add" -> do | ||||||
|           _ ->      -- all other commands: read the journal or fail if missing |             (ensureJournalFileExists =<< (head <$> journalFilePathFromOpts opts)) | ||||||
|             withJournalDo opts (cmdaction opts) |             withJournalDo opts (cmdaction opts) | ||||||
|  |           -- other commands read the journal and should fail if it's missing | ||||||
|  |           _ -> withJournalDo opts (cmdaction opts) | ||||||
|         ) |         ) | ||||||
|         `orShowHelp` cmdmode |         `orShowHelp` cmdmode | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user