From bf4a164a6f832bbb8435c4021a6b019f8e1c29f7 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 8 Mar 2019 08:40:31 -0800 Subject: Allow -o/--output to be used with --print-*. `--print-default-data-file` `--print-highlighting-style` `--print-default-template` Note that `-o` must occur BEFORE the `--print*` command on the command line (this is documented). Closes #5357. --- src/Text/Pandoc/App/CommandLineOptions.hs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/App/CommandLineOptions.hs b/src/Text/Pandoc/App/CommandLineOptions.hs index 4253620f7..14f665aa9 100644 --- a/src/Text/Pandoc/App/CommandLineOptions.hs +++ b/src/Text/Pandoc/App/CommandLineOptions.hs @@ -786,7 +786,10 @@ options = , Option "D" ["print-default-template"] (ReqArg - (\arg _ -> do + (\arg opt -> do + let write = case optOutputFile opt of + Just f -> UTF8.writeFile f + Nothing -> UTF8.hPutStr stdout templ <- runIO $ do setUserDataDir Nothing getDefaultTemplate arg @@ -794,7 +797,7 @@ options = Right "" -> -- e.g. for docx, odt, json: E.throwIO $ PandocCouldNotFindDataFileError ("templates/default." ++ arg) - Right t -> UTF8.hPutStr stdout t + Right t -> write t Left e -> E.throwIO e exitSuccess) "FORMAT") @@ -802,18 +805,24 @@ options = , Option "" ["print-default-data-file"] (ReqArg - (\arg _ -> do + (\arg opt -> do + let write = case optOutputFile opt of + Just f -> BS.writeFile f + Nothing -> BS.hPutStr stdout runIOorExplode $ - readDefaultDataFile arg >>= liftIO . BS.hPutStr stdout + readDefaultDataFile arg >>= liftIO . write exitSuccess) "FILE") "" -- "Print default data file" , Option "" ["print-highlight-style"] (ReqArg - (\arg _ -> do + (\arg opt -> do + let write = case optOutputFile opt of + Just f -> B.writeFile f + Nothing -> B.putStr sty <- fromMaybe pygments <$> lookupHighlightStyle arg - B.putStr $ encodePretty' + write $ encodePretty' defConfig{confIndent = Spaces 4 ,confCompare = keyOrder (map T.pack -- cgit v1.2.3