;;;; Entry point for the clarence application ;; Clarence is a unix filter, meaning it consumes a stream and outputs a ;; transformed stream. (defpackage :clarence/main (:use :cl :net.acdw.clarence) (:export #:main)) (in-package :clarence/main) (defun clarence/command () "Creates and returns the top-level command." (clingon:make-command :name "clarence" :description "A gemtext converter for other formats" :version "1780.4" :license "BSD 3-Clause" :authors '("Case Duckworth ") :usage "[-t FORMAT] [-o FILE] [FILE]" :options (clarence/options) :handler #'clarence/handler)) (defun clarence/options () "The command-line options for `clarence' command." (list (clingon:make-option :string :description "Output format" :short-name #\t :long-name "to" :initial-value "gemtext" :key :to) (clingon:make-option :filepath :description "Output file" :short-name #\o :long-name "output" :key :output))) (defun clarence/handler (cmd) "The top-level handler." (let ((input-file (car (clingon:command-arguments cmd))) (input-stream *standard-input*) (output-format (clingon:getopt cmd :to)) (output-file (clingon:getopt cmd :output)) (output-stream *standard-output*)) (when input-file (setf input-stream (open input-file :direction :input))) (when output-file (setf output-stream (open output-file :direction :output))) (princ (document-string (parse input-stream) :writer output-format) output-stream) (close input-stream) (close output-stream))) (defun main () (let ((app (clarence/command))) (clingon:run app)))