From 423ac382f9e73bf1ca7fc6b400f98db087cd7d22 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 5 Jun 2024 09:21:25 -0500 Subject: Write executable This involved moving `src' to `lib' and making `bin'. `bin' holds the program, which only imports `jimmy.main' from lib. --- bin/jimmy.scm | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 bin/jimmy.scm (limited to 'bin/jimmy.scm') 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 @@ +;;; (jimmy main) --- the program + +(import (chicken file) + (chicken port) + (chicken process-context) + (jimmy main) + args) + +(define opts + (list (args:make-option (t to) (required: "FORMAT") + (string-append "Translate input to FORMAT." + " One of `gemini', `html', or" + " a filename.")) + (args:make-option (n no-extensions) #:none + "Don't use gemtext extensions.") + (args:make-option (T template) (required: "TEMPLATE") + "Wrap the generated text in TEMPLATE.") + (args:make-option (h help) #:none "Display this text" + (usage 0)))) + +(define (usage #!optional (exit-code 1)) + (with-output-to-port (current-error-port) + (lambda () + (print "Usage: " (car (argv)) " [OPTIONS...] [FILE]") + (newline) + (print (args:usage options)) + (print "Report bugs to acdw@acdw.net."))) + (exit exit-code)) + +(define (main args) + (receive (options operands) (args:parse args opts) + (let ((to (alist-ref 'to options)) + (template (alist-ref 'template options))) + + (cond + ((not to)) ; default: gemini + ((equal? to "html") + (import (jimmy html))) + ((file-exists? to) + (load to)) + (else (error "File does not exist" to))) + + (print (apply jimmy (list (car operands) template)))))) + +(cond-expand + (compiling + (main (command-line-arguments))) + (else)) -- cgit 1.4.1-21-gabe81