diff options
Diffstat (limited to 'bin')
-rw-r--r-- | bin/jimmy.scm | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/bin/jimmy.scm b/bin/jimmy.scm new file mode 100644 index 0000000..17e12ba --- /dev/null +++ b/bin/jimmy.scm | |||
@@ -0,0 +1,48 @@ | |||
1 | ;;; (jimmy main) --- the program | ||
2 | |||
3 | (import (chicken file) | ||
4 | (chicken port) | ||
5 | (chicken process-context) | ||
6 | (jimmy main) | ||
7 | args) | ||
8 | |||
9 | (define opts | ||
10 | (list (args:make-option (t to) (required: "FORMAT") | ||
11 | (string-append "Translate input to FORMAT." | ||
12 | " One of `gemini', `html', or" | ||
13 | " a filename.")) | ||
14 | (args:make-option (n no-extensions) #:none | ||
15 | "Don't use gemtext extensions.") | ||
16 | (args:make-option (T template) (required: "TEMPLATE") | ||
17 | "Wrap the generated text in TEMPLATE.") | ||
18 | (args:make-option (h help) #:none "Display this text" | ||
19 | (usage 0)))) | ||
20 | |||
21 | (define (usage #!optional (exit-code 1)) | ||
22 | (with-output-to-port (current-error-port) | ||
23 | (lambda () | ||
24 | (print "Usage: " (car (argv)) " [OPTIONS...] [FILE]") | ||
25 | (newline) | ||
26 | (print (args:usage options)) | ||
27 | (print "Report bugs to acdw@acdw.net."))) | ||
28 | (exit exit-code)) | ||
29 | |||
30 | (define (main args) | ||
31 | (receive (options operands) (args:parse args opts) | ||
32 | (let ((to (alist-ref 'to options)) | ||
33 | (template (alist-ref 'template options))) | ||
34 | |||
35 | (cond | ||
36 | ((not to)) ; default: gemini | ||
37 | ((equal? to "html") | ||
38 | (import (jimmy html))) | ||
39 | ((file-exists? to) | ||
40 | (load to)) | ||
41 | (else (error "File does not exist" to))) | ||
42 | |||
43 | (print (apply jimmy (list (car operands) template)))))) | ||
44 | |||
45 | (cond-expand | ||
46 | (compiling | ||
47 | (main (command-line-arguments))) | ||
48 | (else)) | ||