packages feed

glob-imports 0.0.2.1 → 0.0.3.0

raw patch · 5 files changed

+58/−9 lines, 5 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ GlobImports.Exe: Prefix :: Affix
+ GlobImports.Exe: Suffix :: Affix
+ GlobImports.Exe: data Affix
+ GlobImports.Exe: instance GHC.Classes.Eq GlobImports.Exe.Affix
+ GlobImports.Exe: instance GHC.Show.Show GlobImports.Exe.Affix
- GlobImports.Exe: renderFile :: AllModelsFile -> String -> String
+ GlobImports.Exe: renderFile :: AllModelsFile -> Affix -> String -> String
- GlobImports.Exe: spliceImports :: Source -> SourceContents -> Destination -> Maybe FilePath -> String -> [String] -> Bool -> IO ()
+ GlobImports.Exe: spliceImports :: Source -> SourceContents -> Destination -> Maybe FilePath -> String -> [String] -> Bool -> Affix -> IO ()

Files

ChangeLog.md view
@@ -1,6 +1,9 @@ # Changelog for glob-imports -## Unreleased changes+## 0.0.3.0++- [#7](https://github.com/parsonsmatt/glob-imports/pull/7)+    - Added `--import-qualified` option to allow for `ImportQualifiedPost`.  ## 0.0.2.1 
app/Main.hs view
@@ -12,6 +12,7 @@     , argsPattern :: String     , argsExcludedPrefixes :: String     , argsDebug :: Bool+    , argsImportQualified :: Affix     }     deriving (Show) @@ -27,6 +28,7 @@                 <*> patternParser                 <*> excludedPrefixesParser                 <*> debugParser+                <*> importQualifiedParser             )             mempty   where@@ -54,6 +56,16 @@         switch $             long "debug"                 <> help "Whether to print debug output"+    stringToAffix x = case x of+        "pre" -> Just Prefix+        "post" -> Just Suffix+        _ -> Nothing+    importQualifiedParser =+        option (maybeReader stringToAffix) $+            long "import-qualified"+                <> metavar "AFFIX"+                <> help "pre: import qualified M, post: import M qualified"+                <> value Prefix  main :: IO () main = do@@ -67,6 +79,7 @@         (argsPattern args)         (splitOn ',' (argsExcludedPrefixes args))         (argsDebug args)+        (argsImportQualified args)   where     splitOn _ [] = []     splitOn sep xs =
glob-imports.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack  name:           glob-imports-version:        0.0.2.1+version:        0.0.3.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
@@ -124,8 +124,9 @@     -> String     -> [String]     -> Bool+    -> Affix     -> IO ()-spliceImports (Source src) (SourceContents srcContents) (Destination dest) msearchDir pat prefixes debug = do+spliceImports (Source src) (SourceContents srcContents) (Destination dest) msearchDir pat prefixes debug affix = do     let         (sourceDir, _file) = splitFileName src         searchDir = fromMaybe sourceDir msearchDir@@ -150,7 +151,7 @@                     mapMaybe pathToModule (fmap (searchDir </>) filteredFiles)                 }         output =-            renderFile input srcContents+            renderFile input affix srcContents      writeFile dest output     where@@ -185,9 +186,10 @@  renderFile     :: AllModelsFile+    -> Affix     -> String     -> String-renderFile amf originalContents =+renderFile amf affix originalContents =     concatMap         unlines         [ modulePrior@@ -237,7 +239,11 @@             reverse (concat [remainingModule, newLines, lastImportLine])      newImportLines =-        map (\mod' -> "import qualified " <> moduleName mod') (amfModuleImports amf)+        map+            (\mod' -> case affix of+                Prefix -> "import qualified " <> moduleName mod'+                Suffix -> "import " <> moduleName mod' <> " qualified")+            (amfModuleImports amf)  data Module = Module     { moduleName :: String@@ -300,3 +306,11 @@ stripSuffix :: (Eq a) => [a] -> [a] -> Maybe [a] stripSuffix suffix str =     reverse <$> stripPrefix (reverse suffix) (reverse str)++-- | How to qualify imports.+-- +-- @since 0.0.3.0+data Affix+    = Prefix -- ^ @import qualified M@+    | Suffix -- ^ @import M qualified@+    deriving (Eq, Show)
test/GlobImports/ExeSpec.hs view
@@ -22,14 +22,14 @@                         ]                     }         it "errors without a GLOB_IMPORTS_SPLICE marker" do-            (pure $! length (renderFile allModelsFile (unlines+            (pure $! length (renderFile allModelsFile Prefix (unlines                 [ "module Foo.Bar where"                 , ""                 , "import Blah"                 ])))                 `shouldThrow` anyErrorCall         it "works with a GLOB_IMPORTS_SPLICE marker" do-            renderFile allModelsFile+            renderFile allModelsFile Prefix                 (unlines                     [ "module Foo.Bar where"                     , ""@@ -47,8 +47,27 @@                         , "  [ \"Foo.Bar.Quux\""                         , "  ]"                         ]+        it "works with import qualified post" do+            renderFile allModelsFile Suffix+                (unlines+                    [ "module Foo.Bar where"+                    , ""+                    , "import Blah"+                    , "-- GLOB_IMPORTS_SPLICE"+                    ])+                `shouldBe`+                    unlines+                        [ "module Foo.Bar where"+                        , ""+                        , "import Blah"+                        , "import Foo.Bar.Quux qualified"+                        , "_importedModules :: [String]"+                        , "_importedModules ="+                        , "  [ \"Foo.Bar.Quux\""+                        , "  ]"+                        ]         it "can handle imports after glob import splice" do-            renderFile allModelsFile+            renderFile allModelsFile Prefix                 (unlines                     [ "module Foo.Bar where"                     , ""