packages feed

servant-serf 0.3.1.2 → 0.3.1.3

raw patch · 15 files changed

+141/−137 lines, 15 filesdep +Cabal-syntaxdep −Cabaldep ~basePVP ok

version bump matches the API change (PVP)

Dependencies added: Cabal-syntax

Dependencies removed: Cabal

Dependency ranges changed: base

API changes (from Hackage documentation)

Files

servant-serf.cabal view
@@ -1,7 +1,7 @@ cabal-version: 2.0  name: servant-serf-version: 0.3.1.2+version: 0.3.1.3 synopsis: Automatically generate Servant API modules. description:   = servant-serf@@ -87,8 +87,8 @@ library   autogen-modules: Paths_servant_serf   build-depends:-    base >= 4.14.0 && < 4.17-    , Cabal >= 3.2.0 && < 3.7+    base >= 4.15.0 && < 4.18+    , Cabal-syntax >= 3.6.0 && < 3.9     , directory >= 1.3.6 && < 1.4     , exceptions >= 0.10.4 && < 0.11     , filepath >= 1.4.2 && < 1.5
source/library/ServantSerf.hs view
@@ -1,6 +1,7 @@ module ServantSerf-  ( ServantSerf.Main.defaultMain-  , ServantSerf.Main.mainWith-  ) where+  ( ServantSerf.Main.defaultMain,+    ServantSerf.Main.mainWith,+  )+where  import qualified ServantSerf.Main
source/library/ServantSerf/Exception/ExtraArgument.hs view
@@ -3,7 +3,7 @@ import qualified Control.Monad.Catch as Exception  newtype ExtraArgument-    = ExtraArgument String-    deriving (Eq, Show)+  = ExtraArgument String+  deriving (Eq, Show)  instance Exception.Exception ExtraArgument
source/library/ServantSerf/Exception/InvalidDepth.hs view
@@ -3,7 +3,7 @@ import qualified Control.Monad.Catch as Exception  newtype InvalidDepth-    = InvalidDepth String-    deriving (Eq, Show)+  = InvalidDepth String+  deriving (Eq, Show)  instance Exception.Exception InvalidDepth
source/library/ServantSerf/Exception/InvalidModuleName.hs view
@@ -3,7 +3,7 @@ import qualified Control.Monad.Catch as Exception  newtype InvalidModuleName-    = InvalidModuleName String-    deriving (Eq, Show)+  = InvalidModuleName String+  deriving (Eq, Show)  instance Exception.Exception InvalidModuleName
source/library/ServantSerf/Exception/InvalidOption.hs view
@@ -3,7 +3,7 @@ import qualified Control.Monad.Catch as Exception  newtype InvalidOption-    = InvalidOption String-    deriving (Eq, Show)+  = InvalidOption String+  deriving (Eq, Show)  instance Exception.Exception InvalidOption
source/library/ServantSerf/Exception/MissingArgument.hs view
@@ -3,7 +3,7 @@ import qualified Control.Monad.Catch as Exception  newtype MissingArgument-    = MissingArgument String-    deriving (Eq, Show)+  = MissingArgument String+  deriving (Eq, Show)  instance Exception.Exception MissingArgument
source/library/ServantSerf/Exception/UnknownOption.hs view
@@ -3,7 +3,7 @@ import qualified Control.Monad.Catch as Exception  newtype UnknownOption-    = UnknownOption String-    deriving (Eq, Show)+  = UnknownOption String+  deriving (Eq, Show)  instance Exception.Exception UnknownOption
source/library/ServantSerf/Main.hs view
@@ -29,8 +29,8 @@     Exit.exitSuccess   files <-     Directory.list (Config.depth $ Context.config context)-    . FilePath.dropExtension-    $ Context.source context+      . FilePath.dropExtension+      $ Context.source context   writeFile (Context.output context) $ Module.generate context files  header :: String -> String
source/library/ServantSerf/Module.hs view
@@ -9,43 +9,46 @@  generate :: Context.Context -> [FilePath] -> String generate context files =-  let-    source = Context.source context-    config = Context.config context-    apiName = Config.apiName config-    serverName = Config.serverName config-    moduleName = case Config.moduleName config of-      Nothing ->-        maybe "Main" ModuleName.toString-          . ModuleName.fromFilePath-          $ Context.source context-      Just x -> ModuleName.toString x-    suffix = Config.excludeSuffix config-    moduleNames =-      (if null suffix then id else filter $ not . List.isSuffixOf suffix)-        . fmap ModuleName.toString-        . List.sort-        . Maybe.mapMaybe ModuleName.fromFilePath-        $ filter (FilePath.isExtensionOf "hs") files-  in unlines-    [ "{-# LINE 1 " <> show source <> " #-}"-    , "{-# OPTIONS_GHC -w #-}"-    , ""-    , "module " <> moduleName <> " where"-    , ""-    , "import qualified Servant"-    , ""-    , List.intercalate "\n" $ fmap ("import qualified " <>) moduleNames-    , ""-    , "type " <> apiName-    , "\t= " <> if null moduleNames-      then "Servant.EmptyAPI"-      else List.intercalate "\n\tServant.:<|> "-        $ fmap (<> "." <> apiName) moduleNames-    , ""-    , serverName-    , "\t= " <> if null moduleNames-      then "Servant.emptyServer"-      else List.intercalate "\n\tServant.:<|> "-        $ fmap (<> "." <> serverName) moduleNames-    ]+  let source = Context.source context+      config = Context.config context+      apiName = Config.apiName config+      serverName = Config.serverName config+      moduleName = case Config.moduleName config of+        Nothing ->+          maybe "Main" ModuleName.toString+            . ModuleName.fromFilePath+            $ Context.source context+        Just x -> ModuleName.toString x+      suffix = Config.excludeSuffix config+      moduleNames =+        (if null suffix then id else filter $ not . List.isSuffixOf suffix)+          . fmap ModuleName.toString+          . List.sort+          . Maybe.mapMaybe ModuleName.fromFilePath+          $ filter (FilePath.isExtensionOf "hs") files+   in unlines+        [ "{-# LINE 1 " <> show source <> " #-}",+          "{-# OPTIONS_GHC -w #-}",+          "",+          "module " <> moduleName <> " where",+          "",+          "import qualified Servant",+          "",+          List.intercalate "\n" $ fmap ("import qualified " <>) moduleNames,+          "",+          "type " <> apiName,+          "\t= "+            <> if null moduleNames+              then "Servant.EmptyAPI"+              else+                List.intercalate "\n\tServant.:<|> " $+                  fmap (<> "." <> apiName) moduleNames,+          "",+          serverName,+          "\t= "+            <> if null moduleNames+              then "Servant.emptyServer"+              else+                List.intercalate "\n\tServant.:<|> " $+                  fmap (<> "." <> serverName) moduleNames+        ]
source/library/ServantSerf/Type/Config.hs view
@@ -9,13 +9,13 @@ import qualified ServantSerf.Type.ModuleName as ModuleName  data Config = Config-  { apiName :: String-  , depth :: Depth.Depth-  , excludeSuffix :: String-  , help :: Bool-  , moduleName :: Maybe ModuleName.ModuleName-  , serverName :: String-  , version :: Bool+  { apiName :: String,+    depth :: Depth.Depth,+    excludeSuffix :: String,+    help :: Bool,+    moduleName :: Maybe ModuleName.ModuleName,+    serverName :: String,+    version :: Bool   }   deriving (Eq, Show) @@ -24,25 +24,26 @@  applyFlag :: Exception.MonadThrow m => Config -> Flag.Flag -> m Config applyFlag config flag = case flag of-  Flag.ApiName x -> pure config { apiName = x }+  Flag.ApiName x -> pure config {apiName = x}   Flag.Depth x -> case Depth.fromString x of     Nothing -> Exception.throwM $ InvalidDepth.InvalidDepth x-    Just y -> pure config { depth = y }-  Flag.ExcludeSuffix x -> pure config { excludeSuffix = x }-  Flag.Help -> pure config { help = True }+    Just y -> pure config {depth = y}+  Flag.ExcludeSuffix x -> pure config {excludeSuffix = x}+  Flag.Help -> pure config {help = True}   Flag.ModuleName x -> case ModuleName.fromString x of     Nothing -> Exception.throwM $ InvalidModuleName.InvalidModuleName x-    Just y -> pure config { moduleName = Just y }-  Flag.ServerName x -> pure config { serverName = x }-  Flag.Version -> pure config { version = True }+    Just y -> pure config {moduleName = Just y}+  Flag.ServerName x -> pure config {serverName = x}+  Flag.Version -> pure config {version = True}  initial :: Config-initial = Config-  { apiName = "API"-  , depth = Depth.Deep-  , excludeSuffix = ""-  , help = False-  , moduleName = Nothing-  , serverName = "server"-  , version = False-  }+initial =+  Config+    { apiName = "API",+      depth = Depth.Deep,+      excludeSuffix = "",+      help = False,+      moduleName = Nothing,+      serverName = "server",+      version = False+    }
source/library/ServantSerf/Type/Context.hs view
@@ -10,17 +10,16 @@ import qualified System.Console.GetOpt as Console  data Context = Context-  { config :: Config.Config-  , input :: FilePath-  , output :: FilePath-  , source :: FilePath+  { config :: Config.Config,+    input :: FilePath,+    output :: FilePath,+    source :: FilePath   }   deriving (Eq, Show)  fromArguments :: Exception.MonadThrow m => [String] -> m Context fromArguments arguments = do-  let-    (fs, as, us, is) = Console.getOpt' Console.Permute Flag.options arguments+  let (fs, as, us, is) = Console.getOpt' Console.Permute Flag.options arguments   mapM_ (Exception.throwM . UnknownOption.UnknownOption) us   mapM_ (Exception.throwM . InvalidOption.InvalidOption) is   c <- Config.fromFlags fs@@ -30,4 +29,4 @@     [_, _] -> Exception.throwM $ MissingArgument.MissingArgument "OUTPUT"     s : i : o : xs -> do       mapM_ (Exception.throwM . ExtraArgument.ExtraArgument) xs-      pure Context { config = c, input = i, output = o, source = s }+      pure Context {config = c, input = i, output = o, source = s}
source/library/ServantSerf/Type/Depth.hs view
@@ -1,9 +1,9 @@ module ServantSerf.Type.Depth where  data Depth-    = Deep-    | Shallow-    deriving (Eq, Show)+  = Deep+  | Shallow+  deriving (Eq, Show)  fromString :: String -> Maybe Depth fromString x = case x of
source/library/ServantSerf/Type/Flag.hs view
@@ -3,50 +3,50 @@ import qualified System.Console.GetOpt as Console  data Flag-    = ApiName String-    | Depth String-    | ExcludeSuffix String-    | Help-    | ModuleName String-    | ServerName String-    | Version-    deriving (Eq, Show)+  = ApiName String+  | Depth String+  | ExcludeSuffix String+  | Help+  | ModuleName String+  | ServerName String+  | Version+  deriving (Eq, Show)  options :: [Console.OptDescr Flag] options =   [ Console.Option-    ['h', '?']-    ["help"]-    (Console.NoArg Help)-    "Shows this help message, then exits."-  , Console.Option-    []-    ["version"]-    (Console.NoArg Version)-    "Shows the version number, then exits."-  , Console.Option-    []-    ["api-name"]-    (Console.ReqArg ApiName "API_NAME")-    "Sets the name to use for the API type. Defaults to `API`."-  , Console.Option-    []-    ["depth"]-    (Console.ReqArg Depth "DEPTH")-    "Controls whether to search through only one directory (`shallow`) or recursively (`deep`). Defaults to `deep`."-  , Console.Option-    []-    ["exclude-suffix"]-    (Console.ReqArg ExcludeSuffix "SUFFIX")-    "Sets the module suffix to exclude. Defaults to the empty string."-  , Console.Option-    []-    ["module-name"]-    (Console.ReqArg ModuleName "MODULE_NAME")-    "Sets the name of the generated module. By default this is generated from the source file name."-  , Console.Option-    []-    ["server-name"]-    (Console.ReqArg ServerName "SERVER_NAME")-    "Sets the name to use for the server value. Defaults to `server`."+      ['h', '?']+      ["help"]+      (Console.NoArg Help)+      "Shows this help message, then exits.",+    Console.Option+      []+      ["version"]+      (Console.NoArg Version)+      "Shows the version number, then exits.",+    Console.Option+      []+      ["api-name"]+      (Console.ReqArg ApiName "API_NAME")+      "Sets the name to use for the API type. Defaults to `API`.",+    Console.Option+      []+      ["depth"]+      (Console.ReqArg Depth "DEPTH")+      "Controls whether to search through only one directory (`shallow`) or recursively (`deep`). Defaults to `deep`.",+    Console.Option+      []+      ["exclude-suffix"]+      (Console.ReqArg ExcludeSuffix "SUFFIX")+      "Sets the module suffix to exclude. Defaults to the empty string.",+    Console.Option+      []+      ["module-name"]+      (Console.ReqArg ModuleName "MODULE_NAME")+      "Sets the name of the generated module. By default this is generated from the source file name.",+    Console.Option+      []+      ["server-name"]+      (Console.ReqArg ServerName "SERVER_NAME")+      "Sets the name to use for the server value. Defaults to `server`."   ]
source/library/ServantSerf/Type/ModuleName.hs view
@@ -7,8 +7,8 @@ import qualified System.FilePath as FilePath  newtype ModuleName-    = ModuleName Cabal.ModuleName-    deriving (Eq, Ord, Show)+  = ModuleName Cabal.ModuleName+  deriving (Eq, Ord, Show)  toString :: ModuleName -> String toString (ModuleName x) = Cabal.display x