about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2023-04-03 23:49:19 -0500
committerCase Duckworth2023-04-03 23:49:19 -0500
commitdcff52b29634ffbac9063ee00876d2c979fcf145 (patch)
tree4fcd57785749fdc8a1c721bf2b29c6d45cea9f42
parentChanges and stuff (diff)
downloadwikme-dcff52b29634ffbac9063ee00876d2c979fcf145.tar.gz
wikme-dcff52b29634ffbac9063ee00876d2c979fcf145.zip
Add command line arguments
-rw-r--r--wikme.scm78
-rw-r--r--wikme.sld6
2 files changed, 78 insertions, 6 deletions
diff --git a/wikme.scm b/wikme.scm index a8b4755..3b9a5ae 100644 --- a/wikme.scm +++ b/wikme.scm
@@ -1,9 +1,79 @@
1(import wikme 1;;; Wikme --- executable bit
2;; wikme [options...] [source-directory]
3
4(cond-expand
5 (r7rs)
6 (chicken-5
7 (import (r7rs))))
8
9(import (wikme)
2 (scheme) 10 (scheme)
3 (chicken process-context)) 11 (chicken port)
12 (chicken process-context)
13 (chicken string)
14 (args)
15 (utf8))
16
17(define opts
18 (list (args:make-option (o output) (required: "DIRECTORY")
19 "Write wiki to DIRECTORY.")
20 (args:make-option (b base-url) (required: "URL")
21 "Base url for links.")
22 (args:make-option (t template) (required: "FILE")
23 "Template to expand wiki pages in.")
24 ;; XXX: These don't work at the moment. The functions aren't seen by
25 ;; wikme at runtime, ugh.
26 ;; (args:make-option (S source-transformers) (required: "FUNCTION...")
27 ;; "Functions to transform page source code with.")
28 ;; (args:make-option (P path-transformers) (required: "FUNCTION...")
29 ;; "Functions to transform page paths with.")
30 (args:make-option (x extension) (required: "EXT")
31 "Extension of source files.")
32 (args:make-option (h help) none: "Show this help and exit."
33 (usage))))
34
35(define (usage #!optional exit-code)
36 (with-output-to-port (current-error-port)
37 (lambda ()
38 (print "Usage: " (program-name) " [options...] [INPUT-DIRECTORY]")
39 (print "INPUT-DIRECTORY defaults to the current directory.")
40 (newline)
41 (print (args:usage opts))))
42 (exit 1))
4 43
5(define (main args) 44(define (main args)
6 (build-wiki "./test/" 45 (receive (options params) (args:parse args opts)
7 destination: "./out/")) 46 (define build-wiki-args
47 (let loop ((options options)
48 (it '()))
49 (if (null? options)
50 it
51 (loop (cdr options)
52 (append
53 (let ((this (car options)))
54 (case (car this)
55 ((o output)
56 `(destination: ,(cdr this)))
57 ((b base-url)
58 `(base-url: ,(cdr this)))
59 ((t template)
60 `(base-template: ,(cdr this)))
61 ;; ((S source-transformers)
62 ;; `(source-transformers:
63 ;; ,(map (lambda (fn)
64 ;; (eval (string->symbol fn)))
65 ;; (string-split (cdr this) ","))))
66 ;; ((P path-transformers)
67 ;; `(path-transformers:
68 ;; ,(map (lambda (fn)
69 ;; (eval (string->symbol fn)))
70 ;; (string-split (cdr this) ","))))
71 ((x extension)
72 `(source-extension: ,(cdr this)))))
73 it)))))
74 (apply build-wiki (if (null? params)
75 (current-directory)
76 (car params))
77 build-wiki-args)))
8 78
9(main (command-line-arguments)) 79(main (command-line-arguments))
diff --git a/wikme.sld b/wikme.sld index ca3ddd8..abd0e4e 100644 --- a/wikme.sld +++ b/wikme.sld
@@ -1,5 +1,7 @@
1#+chicken-5 1(cond-expand
2(import (r7rs)) 2 (r7rs)
3 (chicken-5
4 (import (r7rs))))
3 5
4(define-library wikme 6(define-library wikme
5 (import (scheme)) 7 (import (scheme))