1module Main (main) where
4import Control.Monad.Except
5import Control.Monad.Trans (lift)
7import qualified Data.ByteString.Lazy as BSL
10import Data.OpenApi.Compare.Options
11import Data.OpenApi.Compare.Run
12import qualified Data.Text.IO as T
13import qualified Data.Yaml as Yaml
17import Text.Pandoc hiding (report)
18import Text.Pandoc.Builder
23 let parseSchema path =
24 eitherDecodeFileStrict path >>= \case
26 Yaml.decodeFileEither path >>= \case
28 putStrLn "Could not parse as json or yaml"
34 a <- parseSchema (clientFile opts)
35 b <- parseSchema (serverFile opts)
36 let runPandocIO :: PandocIO a -> ExceptT Errors IO a
37 runPandocIO x = lift (runIO x) >>= either (throwError . DocumentError) pure
38 options = def {writerExtensions = githubMarkdownExtensions}
39 write :: Pandoc -> ExceptT Errors IO ()
40 write = case outputMode opts of
41 StdoutMode -> lift . T.putStrLn <=< runPandocIO . writeMarkdown options
42 FileMode f -> case formatFromFilePath f of
43 Nothing -> \_ -> throwError UnknownOutputFormat
44 Just (writer, f') -> lift . BSL.writeFile f' <=< runPandocIO . writer
47 { treeStyle = reportTreeStyle opts
48 , reportMode = fromMaybe All $ mode opts
50 (report, status) = runReport reportConfig (a, b)
52 Just _ -> either handler pure <=< runExceptT $ write $ doc report
54 when (signalExitCode opts) $
56 NoBreakingChanges -> exitSuccess
57 BreakingChanges -> exitWith $ ExitFailure 1
58 OnlyUnsupportedChanges -> exitWith $ ExitFailure 2
61 = DocumentError PandocError
64handler :: Errors -> IO a
65handler (DocumentError err) = do
66 T.hPutStrLn stderr (renderError err)
67 exitWith $ ExitFailure 100
68handler UnknownOutputFormat = do
69 T.hPutStrLn stderr "Could not determine output format from file extension."
70 exitWith $ ExitFailure 101
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list