hledger/bin/hledger-check-tagfiles.hs
Simon Michael 32ccbba805 bin: switch to "runghc", drop "env -S" (#1453)
env -S isn't a thing on linux of course. Go back to using standard
env, which means using a stack options line, which means not using
"ghc". This new setup is probably simpler anyway. I've just had to
give up on the goal of having each script's required packages being
defined in one place; now (to they extent they are required) they
must be defined both in the script header and in compile.sh.
2021-01-12 10:55:00 -08:00

36 lines
950 B
Haskell
Executable File

#!/usr/bin/env stack
-- stack runghc --verbosity info --package hledger
-- See hledger-check-fancyassertions.hs
{-
hledger-check-tagfiles stack script.
Read the default journal and give an error if any tag values
containing '/' do not exist as file paths.
Usage:
$ hledger-check-tagfiles.hs # compiles if needed
or:
$ hledger check-tagfiles # compiles if there's no compiled version
-}
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