2022-02-18 10:22:19 +03:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
{-# LANGUAGE RecordWildCards #-}
|
|
|
|
|
|
|
|
module Main (main) where
|
|
|
|
|
|
|
|
import Options.Applicative
|
|
|
|
( Parser,
|
|
|
|
auto,
|
|
|
|
execParser,
|
|
|
|
flag,
|
|
|
|
fullDesc,
|
|
|
|
header,
|
|
|
|
help,
|
|
|
|
helper,
|
|
|
|
info,
|
2022-11-04 05:52:55 +03:00
|
|
|
infoOption,
|
2022-02-18 10:22:19 +03:00
|
|
|
long,
|
|
|
|
metavar,
|
|
|
|
option,
|
|
|
|
progDesc,
|
|
|
|
short,
|
|
|
|
showDefault,
|
|
|
|
str,
|
|
|
|
strArgument,
|
|
|
|
strOption,
|
|
|
|
switch,
|
|
|
|
value,
|
|
|
|
)
|
|
|
|
import System.Environment (getArgs)
|
|
|
|
import Tie (fileWriter, generate)
|
|
|
|
import Prelude hiding (Option)
|
2022-11-04 05:52:55 +03:00
|
|
|
import Data.Version (showVersion)
|
|
|
|
import Paths_tie (version)
|
2022-02-18 10:22:19 +03:00
|
|
|
|
|
|
|
data Input = Input
|
|
|
|
{ outputDirectory :: FilePath,
|
|
|
|
moduleName :: Text,
|
|
|
|
packageName :: Text,
|
2022-03-24 19:29:49 +03:00
|
|
|
extraPackages :: [Text],
|
2022-02-18 10:22:19 +03:00
|
|
|
inputFile :: FilePath
|
|
|
|
}
|
|
|
|
|
|
|
|
options :: Parser Input
|
|
|
|
options =
|
|
|
|
Input
|
|
|
|
<$> option
|
|
|
|
str
|
|
|
|
( long "output"
|
|
|
|
<> short 'o'
|
|
|
|
<> metavar "DIR"
|
|
|
|
<> showDefault
|
|
|
|
<> value "out"
|
2022-06-13 15:31:33 +03:00
|
|
|
<> help "The directory output"
|
2022-02-18 10:22:19 +03:00
|
|
|
)
|
|
|
|
<*> option
|
|
|
|
str
|
|
|
|
( long "module-name"
|
|
|
|
<> metavar "MODULE"
|
|
|
|
<> showDefault
|
|
|
|
<> value "OpenAPI"
|
2022-06-13 15:31:33 +03:00
|
|
|
<> help "Name of the generated top level module"
|
2022-02-18 10:22:19 +03:00
|
|
|
)
|
|
|
|
<*> option
|
|
|
|
str
|
|
|
|
( long "package-name"
|
|
|
|
<> metavar "PACKAGE"
|
|
|
|
<> showDefault
|
|
|
|
<> value "open-api"
|
2022-06-13 15:31:33 +03:00
|
|
|
<> help "Name of the generated cabal project"
|
2022-02-18 10:22:19 +03:00
|
|
|
)
|
2022-03-24 19:29:49 +03:00
|
|
|
<*> many
|
|
|
|
( option
|
|
|
|
str
|
|
|
|
( long "extra-package"
|
|
|
|
<> metavar "PACKAGE"
|
2022-06-13 15:31:33 +03:00
|
|
|
<> help "Extra packages to include in the generated cabal project"
|
2022-03-24 19:29:49 +03:00
|
|
|
)
|
|
|
|
)
|
2022-02-18 10:22:19 +03:00
|
|
|
<*> strArgument
|
|
|
|
( metavar "FILE"
|
2022-06-13 15:31:33 +03:00
|
|
|
<> help "OpenAPI specification file"
|
2022-02-18 10:22:19 +03:00
|
|
|
)
|
|
|
|
|
2022-11-04 05:52:55 +03:00
|
|
|
versioner :: Parser (a -> a)
|
|
|
|
versioner = infoOption ("tie " <> showVersion version)
|
|
|
|
( long "version"
|
|
|
|
<> help "Print Tie version"
|
|
|
|
)
|
|
|
|
|
2022-02-18 10:22:19 +03:00
|
|
|
main :: IO ()
|
|
|
|
main = do
|
|
|
|
Input {..} <-
|
|
|
|
execParser $
|
|
|
|
info
|
2022-11-04 05:52:55 +03:00
|
|
|
(helper <*> versioner <*> options)
|
2022-02-18 10:22:19 +03:00
|
|
|
( fullDesc
|
|
|
|
<> progDesc "Generate a Haskell server from an OpenAPI3 specification"
|
|
|
|
<> header "tie - openapi3 server code generator"
|
|
|
|
)
|
|
|
|
generate
|
|
|
|
(fileWriter outputDirectory)
|
|
|
|
packageName
|
|
|
|
moduleName
|
2022-03-24 19:29:49 +03:00
|
|
|
extraPackages
|
2022-02-18 10:22:19 +03:00
|
|
|
inputFile
|