Debian Codegraph @

Hledger/Cli/Commands/Files.hs

raw
1 {-|
2
3 The @files@ command lists included files.
4
5 -}
6
7 {-# LANGUAGE TemplateHaskell #-}
8
9 module Hledger.Cli.Commands.Files (
10 filesmode
11 ,files
12 ) where
13
14 import Data.Text qualified as T
15 import Safe (headMay)
16
17 import Hledger
18 import Hledger.Cli.CliOptions
19
20
21 -- | Command line options for this command.
22 filesmode = hledgerCommandMode
23 $(embedFileRelative "Hledger/Cli/Commands/Files.txt")
24 []
25 cligeneralflagsgroups2
26 hiddenflags
27 ([], Just $ argsFlag "[REGEX]")
28
29 -- | The files command.
30 files :: CliOpts -> Journal -> IO ()
31 files CliOpts{rawopts_=rawopts} j = do
32 let args = listofstringopt "args" rawopts
33 regex <- mapM (either fail pure . toRegex . T.pack) $ headMay args
34 let fs = maybe id (filter . regexMatch) regex
35 $ map fst
36 $ jfiles j
37 mapM_ putStrLn fs