tweak journal file auto-creation, add tests
This commit is contained in:
parent
aaf14ffda1
commit
2f6b82122f
@ -96,15 +96,15 @@ ensureJournalFile :: FilePath -> IO ()
|
||||
ensureJournalFile f = do
|
||||
exists <- doesFileExist f
|
||||
when (not exists) $ do
|
||||
printf "No journal file at %s, creating...\n" f
|
||||
printf "Edit this file or use hledger add or hledger web to add transactions.\n"
|
||||
hPrintf stderr "No journal file \"%s\", creating it.\n" f
|
||||
hPrintf stderr "Edit this file or use \"hledger add\" or \"hledger web\" to add transactions.\n"
|
||||
emptyJournal >>= writeFile f
|
||||
|
||||
-- | Give the content for a new auto-created journal file.
|
||||
emptyJournal :: IO String
|
||||
emptyJournal = do
|
||||
d <- getCurrentDay
|
||||
return $ printf "; journal created by hledger on %s\n; see http://hledger.org/MANUAL.html#file-format\n\n" (show d)
|
||||
return $ printf "; journal created %s; see http://hledger.org/MANUAL.html#journal-file\n\n" (show d)
|
||||
|
||||
-- | Read a Journal from this string, using the specified data format or
|
||||
-- trying all known formats, or give an error string.
|
||||
|
||||
10
tests/no-such-file.test
Normal file
10
tests/no-such-file.test
Normal file
@ -0,0 +1,10 @@
|
||||
# commands should generally autocreate an empty journal when missing, see also add*.test
|
||||
# $$ used for safe concurrent test running, may be a bash-ism
|
||||
#
|
||||
rm -f $$; bin/hledger register -f $$; rm -f $$
|
||||
>>>
|
||||
>>>2 /No journal file.*creating it/
|
||||
#
|
||||
rm -f $$; bin/hledger balance --no-total -f $$; rm -f $$
|
||||
>>>
|
||||
>>>2 /No journal file.*creating it/
|
||||
Loading…
Reference in New Issue
Block a user