Let annotator work in batch mode

This commit is contained in:
Alexander Kobjolke 2022-03-09 00:51:14 +01:00
parent 9da29e683a
commit 3c43cd7c5d

View file

@ -50,6 +50,7 @@ data Options = Options
, verbosity :: Verbosity , verbosity :: Verbosity
, showVersion :: Maybe ShowVersion , showVersion :: Maybe ShowVersion
, showHelp :: Bool , showHelp :: Bool
, batchMode :: Bool
, contextLines :: Int , contextLines :: Int
, onlyNewest :: Bool , onlyNewest :: Bool
, annotationFiles :: [FilePath] , annotationFiles :: [FilePath]
@ -64,6 +65,7 @@ defaultOptions = Options
, verbosity = Silent , verbosity = Silent
, showVersion = Nothing , showVersion = Nothing
, showHelp = False , showHelp = False
, batchMode = False
, contextLines = 0 , contextLines = 0
, onlyNewest = True , onlyNewest = True
, annotationFiles = [] , annotationFiles = []
@ -88,6 +90,9 @@ options =
, Option ['h'] ["help"] , Option ['h'] ["help"]
(NoArg (\opts -> opts { showHelp = True })) (NoArg (\opts -> opts { showHelp = True }))
"show usage information" "show usage information"
, Option ['b'] ["batch"]
(NoArg (\opts -> opts { batchMode = True }))
"run in batch mode, i.e. do not ask any questions"
, Option ['a'] ["all"] , Option ['a'] ["all"]
(NoArg (\opts -> opts { onlyNewest = False})) (NoArg (\opts -> opts { onlyNewest = False}))
"handle all defects not just Newest" "handle all defects not just Newest"
@ -152,7 +157,7 @@ defaultMain = do
putStr $ usageInfo header options putStr $ usageInfo header options
exitWith ExitSuccess exitWith ExitSuccess
automaticAnnotations <- rights . concat <$> mapM fromFile (annotationFiles opts) automaticAnnotations <- rights . concat <$> (filterM fileExist (annotationFiles opts) >>= mapM fromFile)
let opts' = opts { autoAnnotations = automaticAnnotations } let opts' = opts { autoAnnotations = automaticAnnotations }
@ -384,8 +389,9 @@ handleViolation content v@Violation{..} = do
, description , description
]) ])
putStrLn (code)) putStrLn (code))
if batchMode opts
then pure $ Nothing
else do
choice <- getUserChoice v choice <- getUserChoice v
case choice of case choice of
Abort -> liftIO $ exitSuccess Abort -> liftIO $ exitSuccess