hledger/bin/hledger-check-tag-files.cabal.hs
2020-08-15 09:51:44 -07:00

36 lines
929 B
Haskell
Executable File

#!/usr/bin/env cabal
{- cabal:
build-depends: base, directory, hledger, text
-}
{-
hledger-check-tag-files cabal script (requires cabal 3+).
Read the default journal and give an error if any tag values
containing '/' do not exist as file paths.
Usage:
$ hledger-check-tag-files.hs # compiles every time (?)
or:
$ hledger check-tag-files # compiles every time (?)
-}
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
when (not exists) $ do
putStrLn $ "file not found in tag: " ++ t ++ ": " ++ f
exitFailure