handle a blank LEDGER_FILE or LEDGER value more gracefully (use the default file path)
This commit is contained in:
parent
eefae63bb6
commit
44709f1e16
@ -112,19 +112,21 @@ emptyJournal = do
|
|||||||
readJournal :: Maybe String -> String -> IO (Either String Journal)
|
readJournal :: Maybe String -> String -> IO (Either String Journal)
|
||||||
readJournal format s = journalFromPathAndString format "(string)" s
|
readJournal format s = journalFromPathAndString format "(string)" s
|
||||||
|
|
||||||
-- | Get the user's default journal file path. Like ledger, we look first
|
-- | Get the user's journal file path. Like ledger, we look first for the
|
||||||
-- for the LEDGER_FILE environment variable, and if that does not exist,
|
-- LEDGER_FILE environment variable, and if that does not exist, for the
|
||||||
-- for the legacy LEDGER environment variable. If neither exists, the path
|
-- legacy LEDGER environment variable. If neither is set, or the value is
|
||||||
-- will be ".hledger.journal" in the users's home directory, or if we
|
-- blank, return the default journal file path, which is
|
||||||
-- cannot determine that, in the current directory.
|
-- ".hledger.journal" in the users's home directory, or if we cannot
|
||||||
|
-- determine that, in the current directory.
|
||||||
myJournalPath :: IO String
|
myJournalPath :: IO String
|
||||||
myJournalPath =
|
myJournalPath = do
|
||||||
getEnv journalenvvar `catch`
|
s <- envJournalPath
|
||||||
(\_ -> do
|
if null s then defaultJournalPath else return s
|
||||||
getEnv journalenvvar2 `catch`
|
where
|
||||||
(\_ -> do
|
envJournalPath = getEnv journalenvvar `catch` (\_ -> getEnv journalenvvar2 `catch` (\_ -> return ""))
|
||||||
home <- getHomeDirectory `catch` (\_ -> return "")
|
defaultJournalPath = do
|
||||||
return $ home </> journaldefaultfilename))
|
home <- getHomeDirectory `catch` (\_ -> return "")
|
||||||
|
return $ home </> journaldefaultfilename
|
||||||
|
|
||||||
-- | Get the user's default timelog file path.
|
-- | Get the user's default timelog file path.
|
||||||
myTimelogPath :: IO String
|
myTimelogPath :: IO String
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user