git.iko.soy/typeable/pandoc
on master help sign in
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

commit5dda65b5dc9213f74f7d33777e002fae903d1cd1 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateMon 8 Jan 2007, 08:11 (20 years ago) parentd47ce5b
4 files changed+83−47
README+31−17 debian/changelog+1−6 man/man1/pandoc.1+21−5 src/Main.hs+30−19
README+31−17
@@ -203,6 +203,7 @@ Command-line options
203203====================
204204
205205Various command-line options can be used to customize the output.
206+For further documentation, see the `pandoc(1)` man page.
206207
207208`-f`, `--from`, `-r`, or `--read` can be used to specify the input
208209format -- the format Pandoc will be converting *from*. Available
@@ -216,8 +217,9 @@ are `native`, `html`, `s5`, `docbook`, `latex`, `markdown`, `rst`, and
216217`-s` or `--standalone` indicates that a standalone document is to be
217218produced (with appropriate headers and footers), rather than a fragment.
218219
219−`-o` or `--output` specifies the name of the output file. If no output
220−filename is given, output will be sent to STDOUT.
220+`-o` or `--output` specifies the name of the output file. If this
221+option is not specified, or if its argument is `-`, output will be sent
222+to STDOUT.
221223
222224`-p` or `--preserve-tabs` causes tabs in the source text to be
223225preserved, rather than converted to spaces (the default).
@@ -284,21 +286,33 @@ is for lists to be displayed all at once.
284286`-N` or `--number-sections` causes sections to be numbered in LaTeX
285287output. By default, sections are not numbered.
286288
287−`-d` or `--debug` causes a debugging message to be written to STDERR.
288−The format of the message is as follows:
289−
290− OUTPUT=foo
291− INPUT=bar
292− INPUT=Foo Baz
293−
294−Here `OUTPUT=` is followed by the name of the output file specified
295−using `-o`, if any. If no output file was specified, `OUTPUT=`
296−will appear with nothing following it. Lines beginning `INPUT=`
297−specify input files. If there are no input files, no `INPUT=` lines
298−will be printed. The `-d` option forces output to be written to
299−STDOUT, even if an output file was specified using the `-o` option.
300−(This option is provided to make it easier to write wrappers for
301−`pandoc`.)
289+`--dump-args` is intended to make it easier to create wrapper scripts
290+that use Pandoc. It causes Pandoc to dump information about the arguments
291+with which it was called to STDOUT, then exit. The first line printed
292+is the name of the output file specified using the `-o` or `--output`
293+option, or `-` if output would go to STDOUT. The remaining lines, if any,
294+list command-line arguments. These will include the names of input
295+files and any special options passed after ` -- ` on the command line.
296+So, for example,
297+
298+ pandoc --dump-args -o foo.html -s foo.txt appendix.txt -- -e latin1
299+
300+will cause the following to be printed to STDOUT:
301+
302+ foo.html
303+ foo.txt
304+ appendix.txt
305+ -e
306+ latin1
307+
308+`--ignore-args` causes Pandoc to ignore all command-line arguments.
309+Regular Pandoc options are not ignored. Thus, for example,
310+
311+ pandoc --ignore-args -o foo.html -s foo.txt -- -e latin1
312+
313+is equivalent to
314+
315+ pandoc -o foo.html -s
302316
303317`-v` or `--version` prints the version number to STDERR.
304318
debian/changelog+1−6
@@ -8,12 +8,7 @@ pandoc (0.3) unstable; urgency=low
88 + Added '--strict' option for maximum compatibility with official
99 Markdown syntax.
1010 + Added '-o/--output' option to send output to a file.
11− + Added '-d/--debug' option:
12− - Prints OUTPUT= followed by output filename (or blank) to stderr.
13− - Prints INPUT= followed by input filename to stderr, for each
14− input file (if any).
15− - Sends output to STDOUT, even if output file was specified.
16− - This is intended mainly to make it easier to write wrappers.
11+ + Added '--dump-args' and '--ignore-args' options (for use in wrappers).
1712 + Modified '-v' and '-h' output to go to STDERR, not STDOUT, and return
1813 error condition (2). This is helpful for writing wrappers.
1914 + Reformatted usage message so that it doesn't wrap illegibly.
man/man1/pandoc.1+21−5
@@ -93,7 +93,8 @@ Produce output with an appropriate header and footer (e.g. a
9393standalone HTML, LaTeX, or RTF file, not a fragment).
9494.TP
9595.B \-o FILE, \-\-output=FILE
96−Write output to \fIFILE\fR instead of STDOUT.
96+Write output to \fIFILE\fR instead of STDOUT. If \fIFILE\fR is
97+`\-', output will go to STDOUT.
9798.TP
9899.B \-p, \-\-preserve-tabs
99100Preserve tabs instead of converting them to spaces.
@@ -151,10 +152,25 @@ markdown, rst, rtf\fR).
151152.B \-T \fISTRING\fB, \-\-title-prefix=\fISTRING\fB
152153Specify \fISTRING\fR as a prefix to the HTML window title.
153154.TP
154−.B \-d, \-\-debug
155−Print debugging information (names of input and output files) to
156−STDERR. Write output to STDOUT, even if an output file was specified
157−using the \fB\-o\fR option.
155+.B \-\-dump\-args
156+Print information about command\-line arguments to STDOUT, then exit.
157+The first line of output contains the name of the output file specified
158+with the \fB\-o\fR option, or `\-' (for STDOUT) if no output file was
159+specified. The remaining lines contain the command\-line arguments,
160+one per line, in the order they appear. These do not include regular
161+Pandoc options and their arguments, but do include any options appearing
162+after a `\-\-' separator at the end of the line.
163+This option is intended primarily for use in wrapper scripts.
164+.TP
165+.B \-\-ignore\-args
166+Ignore command\-line arguments (for use in wrapper scripts).
167+Regular Pandoc options are not ignored. Thus, for example,
168+.IP
169+.B pandoc \-\-ignore\-args \-o foo.html \-s foo.txt -- -e latin1
170+.IP
171+is equivalent to
172+.IP
173+.B pandoc \-o foo.html \-s
158174.TP
159175.B \-v, \-\-version
160176Print version.
src/Main.hs+30−19
@@ -111,7 +111,8 @@ data Opt = Opt
111111 , optIncremental :: Bool -- ^ Use incremental lists in S5
112112 , optSmart :: Bool -- ^ Use smart typography
113113 , optASCIIMathML :: Bool -- ^ Use ASCIIMathML in HTML
114− , optDebug :: Bool -- ^ Output debug messages
114+ , optDumpArgs :: Bool -- ^ Output command-line arguments
115+ , optIgnoreArgs :: Bool -- ^ Ignore command-line arguments
115116 , optStrict :: Bool -- ^ Use strict markdown syntax
116117 }
117118
@@ -130,12 +131,13 @@ defaultOpts = Opt
130131 , optIncludeAfterBody = ""
131132 , optCustomHeader = "DEFAULT"
132133 , optTitlePrefix = ""
133− , optOutputFile = "" -- null for stdout
134+ , optOutputFile = "-" -- "-" means stdout
134135 , optNumberSections = False
135136 , optIncremental = False
136137 , optSmart = False
137138 , optASCIIMathML = False
138− , optDebug = False
139+ , optDumpArgs = False
140+ , optIgnoreArgs = False
139141 , optStrict = False
140142 }
141143
@@ -267,10 +269,15 @@ options =
267269 "FORMAT")
268270 "" -- "Print default header for FORMAT"
269271
270− , Option "d" ["debug"]
272+ , Option "" ["dump-args"]
271273 (NoArg
272− (\opt -> return opt { optDebug = True }))
273− "" -- "Print debug messages to stderr, output to stdout"
274+ (\opt -> return opt { optDumpArgs = True }))
275+ "" -- "Print output filename and arguments to stdout."
276+
277+ , Option "" ["ignore-args"]
278+ (NoArg
279+ (\opt -> return opt { optIgnoreArgs = True }))
280+ "" -- "Ignore command-line arguments."
274281
275282 , Option "v" ["version"]
276283 (NoArg
@@ -278,7 +285,7 @@ options =
278285 prg <- getProgName
279286 hPutStrLn stderr (prg ++ " " ++ version ++
280287 copyrightMessage)
281− exitWith $ ExitFailure 2))
288+ exitWith $ ExitFailure 4))
282289 "" -- "Print version"
283290
284291 , Option "h" ["help"]
@@ -317,7 +324,7 @@ defaultReaderName (x:xs) =
317324
318325-- Determine default writer based on output file extension
319326defaultWriterName :: String -> String
320−defaultWriterName "" = "html" -- no output file
327+defaultWriterName "-" = "html" -- no output file
321328defaultWriterName x =
322329 let x' = map toLower x in
323330 case (matchRegex (mkRegex ".*\\.(.*)") x') of
@@ -341,20 +348,20 @@ defaultWriterName x =
341348
342349main = do
343350
344− args <- getArgs
351+ rawArgs <- getArgs
345352 prg <- getProgName
346353 let compatMode = (prg == "hsmarkdown")
347354
348− let (actions, sources, errors) = if compatMode
349− then ([], args, [])
350− else getOpt Permute options args
355+ let (actions, args, errors) = if compatMode
356+ then ([], rawArgs, [])
357+ else getOpt Permute options rawArgs
351358
352359 if (not (null errors))
353360 then do
354361 name <- getProgName
355362 mapM (\e -> hPutStrLn stderr e) errors
356363 hPutStr stderr (usageMessage name options)
357− exitWith $ ExitFailure 2
364+ exitWith $ ExitFailure 3
358365 else
359366 return ()
360367
@@ -384,10 +391,13 @@ main = do
384391 , optIncremental = incremental
385392 , optSmart = smart
386393 , optASCIIMathML = asciiMathML
387− , optDebug = debug
394+ , optDumpArgs = dumpArgs
395+ , optIgnoreArgs = ignoreArgs
388396 , optStrict = strict
389397 } = opts
390398
399+ let sources = if ignoreArgs then [] else args
400+
391401 -- assign reader and writer based on options and filenames
392402 let readerName' = if null readerName
393403 then defaultReaderName sources
@@ -405,14 +415,15 @@ main = do
405415 Just (w,h) -> return (w, h)
406416 Nothing -> error ("Unknown writer: " ++ writerName')
407417
408− output <- if ((null outputFile) || debug)
418+ output <- if (outputFile == "-")
409419 then return stdout
410420 else openFile outputFile WriteMode
411421
412− if debug
413− then do
414− hPutStrLn stderr ("OUTPUT=" ++ outputFile)
415− hPutStr stderr $ concatMap (\s -> "INPUT=" ++ s ++ "\n") sources
422+ if dumpArgs
423+ then do
424+ hPutStrLn stdout outputFile
425+ mapM (\arg -> hPutStrLn stdout arg) args
426+ exitWith $ ExitSuccess
416427 else return ()
417428
418429 let tabFilter = if preserveTabs then id else (tabsToSpaces tabStop)