git.iko.soy/typeable/compaREST
on master help sign in
Added basic options (#13)
commit16607664c3204e50abc01240e151f8bd277073fc authoriko <ilyakooo0@gmail.com> dateTue 9 Mar 2021, 17:06 (6 years ago) parent44e214b
3 files changed+76−18
openapi-diff.cabal+2 src/OpenAPI/Checker/Options.hs+61 src/OpenAPI/Checker/Run.hs+13−18
openapi-diff.cabal+2
@@ -42,6 +42,7 @@ common common-options
4242 , transformers
4343 , yaml
4444 , attoparsec
45+ , optparse-applicative
4546
4647 default-extensions: ConstraintKinds
4748 , DataKinds
@@ -87,6 +88,7 @@ library
8788 , OpenAPI.Checker.Validate
8889 , OpenAPI.Checker.Validate.Dereference
8990 , OpenAPI.Checker.Validate.Monad
91+ , OpenAPI.Checker.Options
9092
9193executable openapi-diff
9294 import: common-options
src/OpenAPI/Checker/Options.hsnew file+61
@@ -0,0 +1,61 @@
1+module OpenAPI.Checker.Options
2+ ( Options (..),
3+ Mode (..),
4+ optionsParserInfo,
5+ execParser,
6+ )
7+where
8+
9+import GHC.Generics (Generic)
10+import Options.Applicative
11+
12+data Options = Options
13+ { clientFile :: FilePath,
14+ serverFile :: FilePath,
15+ mode :: Mode
16+ }
17+ deriving stock (Generic)
18+
19+data Mode = Silent | OnlyErrors | All
20+
21+optionsParserInfo :: ParserInfo Options
22+optionsParserInfo =
23+ info
24+ (helper <*> optionsParser)
25+ ( fullDesc
26+ <> header "openapi-diff"
27+ <> progDesc "A tool to check compatibility between two OpenApi specifications."
28+ )
29+
30+optionsParser :: Parser Options
31+optionsParser =
32+ Options
33+ <$> strOption
34+ ( short 'c'
35+ <> long "client"
36+ <> help "The specification that will be used for the client of the API."
37+ )
38+ <*> strOption
39+ ( short 's'
40+ <> long "server"
41+ <> help "The specification that will be used for the server of the API."
42+ )
43+ <*> ( flag'
44+ Silent
45+ ( long "silent"
46+ <> help "Silence all output."
47+ )
48+ <|> flag'
49+ OnlyErrors
50+ ( long "only-errors"
51+ <> help "Only report incompatibility errors in the output."
52+ )
53+ <|> flag'
54+ All
55+ ( long "all"
56+ <> help
57+ "Report both incompatible and compatible changes. \
58+ \Compatible changes will not trigger a failure exit code."
59+ )
60+ <|> pure All
61+ )
src/OpenAPI/Checker/Run.hs+13−18
@@ -1,25 +1,20 @@
11module OpenAPI.Checker.Run (runChecker) where
22
3−import Data.Aeson
4−import Data.OpenApi
5−import OpenAPI.Checker.Report
6−import OpenAPI.Checker.Validate
7−
3+import Data.Aeson
4+import OpenAPI.Checker.Options
5+import OpenAPI.Checker.Report
6+import OpenAPI.Checker.Validate
87
98runChecker :: IO ()
109runChecker = do
11− let
12− schemaA = (error "FIXME: not implemented")
13− schemaB = (error "FIXME: not implemented")
14− a <- eitherDecodeFileStrict schemaA >>= \case
15− Left e -> do
16− putStrLn $ "Failed to parse: " ++ schemaA
17− fail e
18− Right s -> pure s
19− b <- eitherDecodeFileStrict schemaB >>= \case
20− Left e -> do
21− putStrLn $ "Failed to parse: " ++ schemaB
22− fail e
23− Right s -> pure s
10+ opts <- execParser optionsParserInfo
11+ let parseSchema path =
12+ eitherDecodeFileStrict path >>= \case
13+ Left e -> do
14+ putStrLn $ "Failed to parse: " ++ path
15+ fail e
16+ Right s -> pure s
17+ a <- parseSchema (clientFile opts)
18+ b <- parseSchema (serverFile opts)
2419 let report = reportCompat a b
2520 printReport report