+(defgeneric execute-command (command args))
+
+(defmethod execute-command (command args)
+ (format *error-output* "Unknown command '~(~A~)'. See 'candle --help'.~%" command))
+
+(defun job-info->line (job-info)
+ (format nil "~A (~A) ~A"
+ (subseq (first job-info) 0 8)
+ (format nil "~{~2,,,'0@A/~2,,,'0@A/~A ~2,,,'0@A:~2,,,'0@A~}"
+ (utils:time-as-list (third job-info) :month :date :year :hr :min))
+ (case (second job-info)
+ (:succeeded (format nil "~c[1;32mPassed~c[0m" #\Esc #\Esc))
+ (:failed (format nil "~c[1;31mFailed~c[0m" #\Esc #\Esc))
+ (:queued "In queue")
+ (:no-candle-file "No candle file present")
+ (:in-progress "In progress"))))
+
+(defmacro standard-cli (cmd options-in args usage remaining-args-required &rest success)
+`(multiple-value-bind (parsed-options remaining-args error) (opera:process-arguments ,options-in ,args)
+ (cond
+ ((opera:option-present :help parsed-options)
+ (format t "~A" ,(if (eql usage :default) `(opera:usage ,cmd ,options-in) usage)))
+ ((eql error :unknown-option)
+ (format *error-output* "Unknown option: ~A. See '~A --help'.~%" (car remaining-args) ,cmd))
+ ((eql error :required-argument-missing)
+ (format *error-output* "Missing argument for ~A. See '~A --help'.~%" (car remaining-args) ,cmd))
+ ((and ,remaining-args-required (not remaining-args)) (format *error-output* "~A required. See 'candle --help'.~%" ,remaining-args-required))
+ (t
+ ,@success))))
+
+;;; Section for ./candle
+
+(defun run ()
+ (standard-cli "candle" (main-options) (cdr sb-ext:*posix-argv*) (main-usage) "Command"
+ (if
+ (and (opera:option-present :port parsed-options) (not (parse-integer (opera:option-argument :port parsed-options) :junk-allowed t)))
+ (format *error-output* "--port requires a number. See 'candle -h'~%")
+ (let
+ ((communication:*query-port*
+ (or
+ (and
+ (opera:option-present :port parsed-options)
+ (parse-integer (opera:option-argument :port parsed-options) :junk-allowed t))
+ 25004)))
+ (execute-command (intern (string-upcase (car remaining-args)) :keyword) (cdr remaining-args))))))
+