commit eb4e22904a73410bbcd0ddf52f3287a08f952d86
parent 78728a728e1df7097b3ac4f7ee8281e29c1d7b70
Author: Matthew Flatt <mflatt@racket-lang.org>
Date: Sun, 19 Jan 2014 15:22:15 -0800
scribble: `++args` for passing command-line arguments to documents
original commit: 392ea2e91d6c51157daa35dd1aa72cca951b6ac9
Diffstat:
2 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/pkgs/scribble-pkgs/scribble-doc/scribblings/scribble/running.scrbl b/pkgs/scribble-pkgs/scribble-doc/scribblings/scribble/running.scrbl
@@ -164,3 +164,22 @@ in @filepath{a.scrbl} and @filepath{b.scrbl}, then
builds @filepath{c.html} with cross-reference links into
@filepath{a.html} and @filepath{b.html}.
+
+@section{Passing Command-Line Arguments to Documents}
+
+When @exec{scribble} loads and renders a document module, by default
+it sets @racket[current-command-line-arguments] to an empty vector.
+Use the @DPFlag{arg} flag (any number of times) to add a string to
+@racket[current-command-line-arguments].
+
+For example,
+
+@commandline{scribble ++arg --mode ++arg fast turtle.scrbl}
+
+causes @racket[(current-command-line-arguments)] to return
+@racket['#("--mode" "fast")] while @filepath{turtle.scrbl} is loaded
+and rendered, which could affect the content that
+@filepath{turtle.scrbl} generates if it uses
+@racket[current-command-line-arguments].
+
+@history[#:changed "1.1" @elem{Added the empty-vector default and @DPFlag{arg} flag.}]
+\ No newline at end of file
diff --git a/pkgs/scribble-pkgs/scribble-lib/scribble/run.rkt b/pkgs/scribble-pkgs/scribble-lib/scribble/run.rkt
@@ -30,6 +30,7 @@
(define current-directory-depth (make-parameter 0))
(define current-quiet (make-parameter #f))
(define helper-file-prefix (make-parameter #f))
+(define doc-command-line-arguments (make-parameter null))
(define (read-one str)
(let ([i (open-input-string str)])
@@ -119,18 +120,23 @@
[("++info-in") file "load format-specific cross-ref info from <file>"
(current-info-input-files
(cons file (current-info-input-files)))]
+ [("++arg") arg "add <arg> to current-command-line-arguments"
+ (doc-command-line-arguments
+ (cons arg (doc-command-line-arguments)))]
#:once-each
[("--quiet") "suppress output-file and undefined-tag reporting"
(current-quiet #t)]
#:args (file . another-file)
(let ([files (cons file another-file)])
- (build-docs (map (lambda (file)
- ;; Try `doc' submodule, first:
- (if (module-declared? `(submod (file ,file) doc) #t)
- (dynamic-require `(submod (file ,file) doc) 'doc)
- (dynamic-require `(file ,file) 'doc)))
- files)
- files))))
+ (parameterize ([current-command-line-arguments
+ (list->vector (reverse (doc-command-line-arguments)))])
+ (build-docs (map (lambda (file)
+ ;; Try `doc' submodule, first:
+ (if (module-declared? `(submod (file ,file) doc) #t)
+ (dynamic-require `(submod (file ,file) doc) 'doc)
+ (dynamic-require `(file ,file) 'doc)))
+ files)
+ files)))))
(define (build-docs docs files)
(when (and (current-dest-name)