glob-imports 0.0.4.0 → 0.0.5.0
raw patch · 4 files changed
+20/−14 lines, 4 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- GlobImports.Exe: getFiles :: FilePath -> String -> IO (Either String [FilePath])
+ GlobImports.Exe: getFiles :: FilePath -> [String] -> IO (Either String [FilePath])
- GlobImports.Exe: spliceImports :: Source -> SourceContents -> Destination -> Maybe FilePath -> String -> [String] -> Bool -> Affix -> IO ()
+ GlobImports.Exe: spliceImports :: Source -> SourceContents -> Destination -> Maybe FilePath -> [String] -> [String] -> Bool -> Affix -> IO ()
Files
- ChangeLog.md +5/−0
- app/Main.hs +5/−5
- glob-imports.cabal +1/−1
- src/GlobImports/Exe.hs +9/−8
ChangeLog.md view
@@ -1,5 +1,10 @@ # Changelog for glob-imports +## 0.0.5.0++- [#9](https://github.com/parsonsmatt/glob-imports/pull/9)+ - The `--pattern` option now accepts multiple patterns, separated by commas.+ ## 0.0.4.0 - [#8](https://github.com/parsonsmatt/glob-imports/pull/8)
app/Main.hs view
@@ -43,14 +43,14 @@ patternParser = option str $ long "pattern"- <> metavar "PATTERN"- <> help "Pattern on which to match file paths"+ <> metavar "PATTERN[,PATTERN...]"+ <> help "Patterns on which to match file paths (comma separated)" <> value "**/*.hs" excludedPrefixesParser = option str $ long "exclude-prefixes"- <> metavar "PREFIXES"- <> help "File path prefixes to exclude"+ <> metavar "PREFIX[,PREFIX...]"+ <> help "File path prefixes to exclude (comma separated)" <> value "" debugParser = switch $@@ -76,7 +76,7 @@ (SourceContents $ contents) (Destination $ argsDest args) (argsSearchDir args)- (argsPattern args)+ (splitOn ',' (argsPattern args)) (splitOn ',' (argsExcludedPrefixes args)) (argsDebug args) (argsImportQualified args)
glob-imports.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: glob-imports-version: 0.0.4.0+version: 0.0.5.0 synopsis: Import modules for metaprogramming description: This package provides an executable for importing modules in a directory and splicing those in. Please see the README on GitHub at <https://github.com/parsonsmatt/glob-imports#readme> category: Metaprogramming
src/GlobImports/Exe.hs view
@@ -121,21 +121,21 @@ -> SourceContents -> Destination -> Maybe FilePath- -> String -> [String]+ -> [String] -> Bool -> Affix -> IO ()-spliceImports (Source src) (SourceContents srcContents) (Destination dest) msearchDir pat prefixes debug affix = do+spliceImports (Source src) (SourceContents srcContents) (Destination dest) msearchDir pats prefixes debug affix = do let (sourceDir, _file) = splitFileName src searchDir = fromMaybe sourceDir msearchDir excludePrefixFilter target = not $ any (`isPrefixOf` target) prefixes printDebug debug $ "searching directory: " ++ searchDir- printDebug debug $ "searching with pattern: " ++ pat+ printDebug debug $ "searching with patterns: " ++ show pats printDebug debug $ "excluding file name: " ++ src- eitherFiles <- fmap (filter (essentiallyDistinct src)) <$> getFiles searchDir pat+ eitherFiles <- fmap (filter (essentiallyDistinct src)) <$> getFiles searchDir pats files <- case eitherFiles of Left e -> error e Right f -> pure f@@ -163,12 +163,13 @@ -- | Returns a sorted list of relative paths to all files in the given directory. getFiles :: FilePath- -- ^ The glob pattern to filter with.- -> String -- ^ The directory to search.+ -> [String]+ -- ^ The glob patterns to filter with. -> IO (Either String [FilePath])-getFiles baseDir pat = do- (exitCode, out, err) <- (readProcess $ proc "find" [baseDir, "-wholename", pat]) `catch` handler+getFiles baseDir pats = do+ let findExpr = intercalate ["-o"] (map (\p -> ["-wholename", p]) pats)+ (exitCode, out, err) <- (readProcess $ proc "find" ([baseDir, "("] ++ findExpr ++ [")"])) `catch` handler pure $ case exitCode of ExitSuccess -> Right . sort . lines . Text.unpack . decodeUtf8 . LBS.toStrict $ out ExitFailure _ -> Left . Text.unpack . decodeUtf8 . LBS.toStrict $ err