git.iko.soy/typeable/pandoc
on master help sign in
Added a `--quiet` option to suppress warnings.

Use this also in Tests.Old.

commit63dc6bd02509eb31d9d221c4e39f18af2b77fe6d authorJohn MacFarlane <jgm@berkeley.edu> dateSat 3 Dec 2016, 17:17 (10 years ago) parent2710fc4
3 files changed+24−11
MANUAL.txt+4 pandoc.hs+19−10 tests/Tests/Old.hs+1−1
MANUAL.txt+4
@@ -340,6 +340,10 @@ General options
340340: Give verbose debugging output. Currently this only has an effect
341341 with PDF output.
342342
343+`--quiet`
344+
345+: Suppress warning messages.
346+
343347`--list-input-formats`
344348
345349: List supported input formats, one per line.
pandoc.hs+19−10
@@ -197,6 +197,7 @@ data Opt = Opt
197197 , optDumpArgs :: Bool -- ^ Output command-line arguments
198198 , optIgnoreArgs :: Bool -- ^ Ignore command-line arguments
199199 , optVerbose :: Bool -- ^ Verbose diagnostic output
200+ , optQuiet :: Bool -- ^ Suppress warnings
200201 , optReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst
201202 , optReferenceLocation :: ReferenceLocation -- ^ location for footnotes and link references in markdown output
202203 , optDpi :: Int -- ^ Dpi
@@ -262,6 +263,7 @@ defaultOpts = Opt
262263 , optDumpArgs = False
263264 , optIgnoreArgs = False
264265 , optVerbose = False
266+ , optQuiet = False
265267 , optReferenceLinks = False
266268 , optReferenceLocation = EndOfDocument
267269 , optDpi = 96
@@ -904,6 +906,11 @@ options =
904906 (\opt -> return opt { optVerbose = True }))
905907 "" -- "Verbose diagnostic output."
906908
909+ , Option "" ["quiet"]
910+ (NoArg
911+ (\opt -> return opt { optQuiet = True }))
912+ "" -- "Suppress warnings."
913+
907914 , Option "" ["bash-completion"]
908915 (NoArg
909916 (\_ -> do
@@ -1188,6 +1195,7 @@ convertWithOpts opts args = do
11881195 , optDumpArgs = dumpArgs
11891196 , optIgnoreArgs = ignoreArgs
11901197 , optVerbose = verbose
1198+ , optQuiet = quiet
11911199 , optReferenceLinks = referenceLinks
11921200 , optReferenceLocation = referenceLocation
11931201 , optDpi = dpi
@@ -1407,6 +1415,11 @@ convertWithOpts opts args = do
14071415 then handleIncludes
14081416 else return . Right
14091417
1418+ let runIO' = runIOorExplode .
1419+ (if quiet
1420+ then id
1421+ else withWarningsToStderr)
1422+
14101423 let sourceToDoc :: [FilePath] -> IO (Pandoc, MediaBag)
14111424 sourceToDoc sources' =
14121425 case reader of
@@ -1414,14 +1427,12 @@ convertWithOpts opts args = do
14141427 srcs <- convertTabs . intercalate "\n" <$> readSources sources'
14151428 doc <- handleIncludes' srcs
14161429 case doc of
1417− Right doc' -> runIOorExplode $ withMediaBag
1418− $ withWarningsToStderr
1419− $ r readerOpts doc'
1430+ Right doc' -> runIO' $ withMediaBag
1431+ $ r readerOpts doc'
14201432 Left e -> error $ show e
14211433 ByteStringReader r -> readFiles sources' >>=
1422− (\bs -> runIOorExplode $ withMediaBag
1423− $ withWarningsToStderr
1424− $ r readerOpts bs)
1434+ (\bs -> runIO' $ withMediaBag
1435+ $ r readerOpts bs)
14251436
14261437 -- We parse first if (1) fileScope is set, (2), it's a binary
14271438 -- reader, or (3) we're reading JSON. This is easier to do of an AND
@@ -1493,8 +1504,7 @@ convertWithOpts opts args = do
14931504
14941505 case writer of
14951506 -- StringWriter f -> f writerOptions doc' >>= writerFn outputFile
1496− ByteStringWriter f -> (runIOorExplode $ withWarningsToStderr
1497− $ f writerOptions doc')
1507+ ByteStringWriter f -> (runIO' $ f writerOptions doc')
14981508 >>= writeFnBinary outputFile
14991509 StringWriter f
15001510 | pdfOutput -> do
@@ -1529,6 +1539,5 @@ convertWithOpts opts args = do
15291539 handleEntities = if htmlFormat && ascii
15301540 then toEntities
15311541 else id
1532− output <- runIOorExplode $ withWarningsToStderr
1533− $ f writerOptions doc'
1542+ output <- runIO' $ f writerOptions doc'
15341543 selfcontain (output ++ ['\n' | not standalone']) >>= writerFn outputFile . handleEntities
tests/Tests/Old.hs+1−1
@@ -261,7 +261,7 @@ testWithNormalize normalizer testname opts inp norm = testCase testname $ do
261261 (outputPath, hOut) <- openTempFile "" "pandoc-test"
262262 let inpPath = inp
263263 let normPath = norm
264− let options = ["--data-dir", ".." </> "data"] ++ [inpPath] ++ opts
264+ let options = ["--quiet", "--data-dir", ".." </> "data"] ++ [inpPath] ++ opts
265265 let cmd = pandocPath ++ " " ++ unwords options
266266 let findDynlibDir [] = Nothing
267267 findDynlibDir ("build":xs) = Just $ joinPath (reverse xs) </> "build"