diff options
author | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2007-01-08 08:11:08 +0000 |
---|---|---|
committer | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2007-01-08 08:11:08 +0000 |
commit | 5dda65b5dc9213f74f7d33777e002fae903d1cd1 (patch) | |
tree | 25de8416fc5755a235b428eb8aaf2e023121d5af /src | |
parent | d47ce5b1f444c9754bfe78733c5658616263522a (diff) | |
download | pandoc-5dda65b5dc9213f74f7d33777e002fae903d1cd1.tar.gz |
Changes to Pandoc's options to facilitate wrapper scripts:
+ removed -d/--debug option
+ added --dump-args option, which prints the name of the output file
(or '-' for STDOUT) and all the command-line arguments (excluding
Pandoc options and their arguments), one per line, then exits. Note
that special wrapper options will be treated as arguments if they
follow '--' at the end of the command line. Thus,
pandoc --dump-args -o foo.html foo.txt -- -e latin1
will print the following to STDOUT:
foo.html
foo.txt
-e
latin1
+ added --ignore-args option, which causes Pandoc to ignore all
(non-option) arguments, including any special options that occur
after '--' at the end of the command line.
+ '-' now means STDIN as the name of an input file, STDOUT as the
name of an output file. So,
pandoc -o - -
will take input from STDIN and print output to STDOUT. Note that
if multiple '-o' options are specified on the same line, the last
one takes precedence. So, in a script,
pandoc "$@" -o -
will guarantee output to STDOUT, even if the '-o' option was used.
+ documented these changes in man pages, README, and changelog.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@454 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src')
-rw-r--r-- | src/Main.hs | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/src/Main.hs b/src/Main.hs index b5de582d3..32576074b 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -111,7 +111,8 @@ data Opt = Opt , optIncremental :: Bool -- ^ Use incremental lists in S5 , optSmart :: Bool -- ^ Use smart typography , optASCIIMathML :: Bool -- ^ Use ASCIIMathML in HTML - , optDebug :: Bool -- ^ Output debug messages + , optDumpArgs :: Bool -- ^ Output command-line arguments + , optIgnoreArgs :: Bool -- ^ Ignore command-line arguments , optStrict :: Bool -- ^ Use strict markdown syntax } @@ -130,12 +131,13 @@ defaultOpts = Opt , optIncludeAfterBody = "" , optCustomHeader = "DEFAULT" , optTitlePrefix = "" - , optOutputFile = "" -- null for stdout + , optOutputFile = "-" -- "-" means stdout , optNumberSections = False , optIncremental = False , optSmart = False , optASCIIMathML = False - , optDebug = False + , optDumpArgs = False + , optIgnoreArgs = False , optStrict = False } @@ -267,10 +269,15 @@ options = "FORMAT") "" -- "Print default header for FORMAT" - , Option "d" ["debug"] + , Option "" ["dump-args"] (NoArg - (\opt -> return opt { optDebug = True })) - "" -- "Print debug messages to stderr, output to stdout" + (\opt -> return opt { optDumpArgs = True })) + "" -- "Print output filename and arguments to stdout." + + , Option "" ["ignore-args"] + (NoArg + (\opt -> return opt { optIgnoreArgs = True })) + "" -- "Ignore command-line arguments." , Option "v" ["version"] (NoArg @@ -278,7 +285,7 @@ options = prg <- getProgName hPutStrLn stderr (prg ++ " " ++ version ++ copyrightMessage) - exitWith $ ExitFailure 2)) + exitWith $ ExitFailure 4)) "" -- "Print version" , Option "h" ["help"] @@ -317,7 +324,7 @@ defaultReaderName (x:xs) = -- Determine default writer based on output file extension defaultWriterName :: String -> String -defaultWriterName "" = "html" -- no output file +defaultWriterName "-" = "html" -- no output file defaultWriterName x = let x' = map toLower x in case (matchRegex (mkRegex ".*\\.(.*)") x') of @@ -341,20 +348,20 @@ defaultWriterName x = main = do - args <- getArgs + rawArgs <- getArgs prg <- getProgName let compatMode = (prg == "hsmarkdown") - let (actions, sources, errors) = if compatMode - then ([], args, []) - else getOpt Permute options args + let (actions, args, errors) = if compatMode + then ([], rawArgs, []) + else getOpt Permute options rawArgs if (not (null errors)) then do name <- getProgName mapM (\e -> hPutStrLn stderr e) errors hPutStr stderr (usageMessage name options) - exitWith $ ExitFailure 2 + exitWith $ ExitFailure 3 else return () @@ -384,10 +391,13 @@ main = do , optIncremental = incremental , optSmart = smart , optASCIIMathML = asciiMathML - , optDebug = debug + , optDumpArgs = dumpArgs + , optIgnoreArgs = ignoreArgs , optStrict = strict } = opts + let sources = if ignoreArgs then [] else args + -- assign reader and writer based on options and filenames let readerName' = if null readerName then defaultReaderName sources @@ -405,14 +415,15 @@ main = do Just (w,h) -> return (w, h) Nothing -> error ("Unknown writer: " ++ writerName') - output <- if ((null outputFile) || debug) + output <- if (outputFile == "-") then return stdout else openFile outputFile WriteMode - if debug - then do - hPutStrLn stderr ("OUTPUT=" ++ outputFile) - hPutStr stderr $ concatMap (\s -> "INPUT=" ++ s ++ "\n") sources + if dumpArgs + then do + hPutStrLn stdout outputFile + mapM (\arg -> hPutStrLn stdout arg) args + exitWith $ ExitSuccess else return () let tabFilter = if preserveTabs then id else (tabsToSpaces tabStop) |