2021-01-12 21:55:00 +03:00
|
|
|
#!/usr/bin/env stack
|
|
|
|
-- stack runghc --verbosity info --package hledger
|
2021-01-12 22:07:29 +03:00
|
|
|
-- Run from inside the hledger source tree, or compile with compile.sh.
|
|
|
|
-- See hledger-check-fancyassertions.hs.
|
2020-08-15 19:59:59 +03:00
|
|
|
|
2020-03-28 03:21:23 +03:00
|
|
|
{-
|
2020-11-27 23:29:39 +03:00
|
|
|
hledger-check-tagfiles stack script.
|
2020-03-28 03:21:23 +03:00
|
|
|
Read the default journal and give an error if any tag values
|
|
|
|
containing '/' do not exist as file paths.
|
|
|
|
Usage:
|
2020-03-28 02:43:14 +03:00
|
|
|
|
2020-11-27 23:29:39 +03:00
|
|
|
$ hledger-check-tagfiles.hs # compiles if needed
|
2020-03-28 03:21:23 +03:00
|
|
|
|
|
|
|
or:
|
|
|
|
|
2020-11-27 23:29:39 +03:00
|
|
|
$ hledger check-tagfiles # compiles if there's no compiled version
|
2020-03-28 03:21:23 +03:00
|
|
|
-}
|
2020-03-28 02:43:14 +03:00
|
|
|
|
|
|
|
import Control.Monad
|
|
|
|
import qualified Data.Text as T
|
|
|
|
import Hledger.Cli
|
|
|
|
import System.Directory
|
|
|
|
import System.Exit
|
|
|
|
|
|
|
|
main = withJournalDo defcliopts $ \j -> do
|
|
|
|
let filetags = [ (t,v)
|
|
|
|
| (t',v') <- concatMap transactionAllTags $ jtxns j
|
|
|
|
, let t = T.unpack t'
|
|
|
|
, let v = T.unpack v'
|
|
|
|
, '/' `elem` v
|
|
|
|
]
|
|
|
|
forM_ filetags $ \(t,f) -> do
|
|
|
|
exists <- doesFileExist f
|
2021-08-16 07:57:15 +03:00
|
|
|
unless exists $ do
|
2020-03-28 02:43:14 +03:00
|
|
|
putStrLn $ "file not found in tag: " ++ t ++ ": " ++ f
|
|
|
|
exitFailure
|