about summary refs log tree commit diff stats
path: root/bin/jimmy.scm
blob: 07bad7acfad54f61963f74f7f132644bbd392267 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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 opts))
      (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))