aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2009-08-22 02:26:51 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2009-08-22 02:26:51 +0000
commit6191a1fa745c067d3df153b244e9829255600f5d (patch)
tree01a24adfe7cc3f07dbe466e103fd4e8dd57e6b5b /src
parent69a84f7b14a27d1c947f1e24a339be982cd25cf1 (diff)
downloadpandoc-6191a1fa745c067d3df153b244e9829255600f5d.tar.gz
Fixed markdown2pdf.hs to accept --longopt=val options.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@1607 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src')
-rw-r--r--src/markdown2pdf.hs23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/markdown2pdf.hs b/src/markdown2pdf.hs
index 6a04999fa..75d8c82e6 100644
--- a/src/markdown2pdf.hs
+++ b/src/markdown2pdf.hs
@@ -1,6 +1,6 @@
module Main where
-import Data.List (isInfixOf, intercalate, (\\))
+import Data.List (isInfixOf, intercalate, isPrefixOf)
import Data.Maybe (isNothing)
import Control.Monad (when, unless, guard)
@@ -155,21 +155,26 @@ main = bracket
unless (null miss) $ exit $! "Could not find " ++ intercalate ", " miss
args <- getArgs
-- check for invalid arguments and print help message if needed
- let goodopts = ["-f","-r","--from","--read","--strict","-N",
- "-p","--preserve-tabs","--tab-stop","-R","--parse-raw",
+ let goodopts = ["-f","-r","-N", "-p","-R","-H","-B","-A", "-C","-o"]
+ let goodoptslong = ["--from","--read","--strict",
+ "--preserve-tabs","--tab-stop","--parse-raw",
"--toc","--table-of-contents",
- "--number-sections","-H","--include-in-header",
- "-B","--include-before-body","-A","--include-after-body",
- "-C","--custom-header","-o","--output"]
- let goodoptsLong = filter (\op -> length op > 2) goodopts
+ "--number-sections","--include-in-header",
+ "--include-before-body","--include-after-body",
+ "--custom-header","--output"]
let isOpt ('-':_) = True
isOpt _ = False
- unless (null (filter isOpt args \\ goodopts)) $ do
+ let opts = filter isOpt args
+ -- note that a long option can come in this form: --opt=val
+ let isGoodopt x = x `elem` (goodopts ++ goodoptslong) ||
+ any (\o -> (o ++ "=") `isPrefixOf` x) goodoptslong
+ unless (all isGoodopt opts) $ do
(code, out, _err) <- readProcessWithExitCode "pandoc" ["--help"] ""
putStrLn "markdown2pdf [OPTIONS] [FILES]\nOptions:"
putStr $ unlines $
- filter (\l -> any (`isInfixOf` l) goodoptsLong) $ lines out
+ filter (\l -> any (`isInfixOf` l) goodoptslong) $ lines out
exitWith code
+
-- parse arguments
-- if no input given, use 'stdin'
pandocArgs <- parsePandocArgs args