lib: use glob matching if filename in 'include' directive is a glob pattern
This commit is contained in:
parent
96f7a03487
commit
0ade323d2a
@ -94,6 +94,7 @@ import Text.Megaparsec.Char
|
|||||||
import Text.Megaparsec.Custom
|
import Text.Megaparsec.Custom
|
||||||
import Text.Printf
|
import Text.Printf
|
||||||
import System.FilePath
|
import System.FilePath
|
||||||
|
import System.FilePath.Glob hiding (match)
|
||||||
|
|
||||||
import Hledger.Data
|
import Hledger.Data
|
||||||
import Hledger.Read.Common
|
import Hledger.Read.Common
|
||||||
@ -189,15 +190,18 @@ includedirectivep :: MonadIO m => JournalParser m ()
|
|||||||
includedirectivep = do
|
includedirectivep = do
|
||||||
string "include"
|
string "include"
|
||||||
lift (skipSome spacenonewline)
|
lift (skipSome spacenonewline)
|
||||||
filename <- T.unpack <$> takeWhileP Nothing (/= '\n') -- don't consume newline yet
|
fileglob <- T.unpack <$> takeWhileP Nothing (/= '\n') -- don't consume newline yet
|
||||||
|
|
||||||
parentpos <- getPosition
|
parentpos <- getPosition
|
||||||
|
|
||||||
curdir <- lift $ expandPath (takeDirectory $ sourceName parentpos) ""
|
curdir <- lift $ expandPath (takeDirectory $ sourceName parentpos) ""
|
||||||
`orRethrowIOError` (show parentpos ++ " locating " ++ filename)
|
`orRethrowIOError` (show parentpos ++ " locating " ++ fileglob)
|
||||||
-- </> correctly handles case when 'filename' is absolute
|
|
||||||
let filepaths = [curdir </> filename]
|
filepaths <- if isLiteral (compile fileglob)
|
||||||
-- read child inputs
|
-- </> and globDir1 correctly handle case when 'fileglob' is absolute
|
||||||
|
then pure [curdir </> fileglob]
|
||||||
|
else liftIO $ globDir1 (compile fileglob) curdir
|
||||||
|
|
||||||
forM_ filepaths $ parseChild parentpos
|
forM_ filepaths $ parseChild parentpos
|
||||||
|
|
||||||
void newline
|
void newline
|
||||||
|
|||||||
@ -72,6 +72,7 @@ dependencies:
|
|||||||
- utf8-string >=0.3.5
|
- utf8-string >=0.3.5
|
||||||
- HUnit
|
- HUnit
|
||||||
- extra
|
- extra
|
||||||
|
- Glob >= 0.9
|
||||||
# for ledger-parse:
|
# for ledger-parse:
|
||||||
#- parsers >=0.5
|
#- parsers >=0.5
|
||||||
#- system-filepath
|
#- system-filepath
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user