hledger/hledger/Hledger/Cli/Commands/Files.hs
Simon Michael c80c72d7cd dev: lib, cli, bin: enable/fix name shadowing warnings
And a few other cleanups.
2022-08-23 12:16:15 +01:00

38 lines
782 B
Haskell

{-|
The @files@ command lists included files.
-}
{-# LANGUAGE TemplateHaskell #-}
module Hledger.Cli.Commands.Files (
filesmode
,files
) where
import qualified Data.Text as T
import Safe (headMay)
import Hledger
import Hledger.Cli.CliOptions
-- | Command line options for this command.
filesmode = hledgerCommandMode
$(embedFileRelative "Hledger/Cli/Commands/Files.txt")
[]
[generalflagsgroup2]
[]
([], Just $ argsFlag "[REGEX]")
-- | The files command.
files :: CliOpts -> Journal -> IO ()
files CliOpts{rawopts_=rawopts} j = do
let args = listofstringopt "args" rawopts
regex <- mapM (either fail pure . toRegex . T.pack) $ headMay args
let fs = maybe id (filter . regexMatch) regex
$ map fst
$ jfiles j
mapM_ putStrLn fs