bin: hledger-check-tag-files2, a version using cabal's v2-run command
This commit is contained in:
		
							parent
							
								
									a38694b247
								
							
						
					
					
						commit
						b78b98e372
					
				
							
								
								
									
										35
									
								
								bin/hledger-check-tag-files2.hs
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										35
									
								
								bin/hledger-check-tag-files2.hs
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,35 @@ | ||||
| #!/usr/bin/env cabal | ||||
| {- cabal: | ||||
| build-depends: base, directory, hledger-lib, hledger, text | ||||
| -} | ||||
| {- | ||||
| hledger-check-tag-files script (cabal version, requires cabal-install 3.0.0.0+) | ||||
| 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 if needed | ||||
| 
 | ||||
| or: | ||||
| 
 | ||||
| $ hledger check-tag-files       # 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 | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user