Satisfy style checker
[candle] / src / main / server-cli.lisp
1 (in-package #:candle-server-cli)
2
3 (defvar *options*
4  '((:name :help :short "h" :long "help" :description "Print this usage.")
5    (:name :port :short "p" :long "port" :takes-argument t :variable-name "PORT"
6     :description "Port on which to listen for commands.  Defaults to 25004")
7    (:name :dir :long "candle-dir" :takes-argument t :variable-name "DIR"
8     :description "Directory for candle related data.  Will be created if does not exist.  Defaults to /opt/candle/")
9    (:name :system :long "system" :takes-argument t :variable-name "SYSTEM"
10     :description "System on which to run jobs.  Currently available are local and aws.  Defaults to local.")))
11
12 (defun usage ()
13  (format t "~A"
14   (opera:usage
15    "candle-server"
16    *options*
17    "Starts a candle continuous integration server.  Use 'candle' to interact with the server.")))
18
19 (defun run ()
20  (multiple-value-bind (options remaining-args error) (opera:process-arguments *options* (cdr sb-ext:*posix-argv*))
21   (cond
22    ((opera:option-present :help options) (usage))
23    (remaining-args
24     (format *error-output* "Don't understand ~A.  See 'candle-server -h'~%" (car remaining-args))
25     (sb-ext:exit :code 1))
26    ((and
27      (opera:option-present :port options)
28      (not (parse-integer (opera:option-argument :port options) :junk-allowed t)))
29     (format *error-output* "--port requires a number.  See 'candle-server -h'~%"))
30    (t
31     (let
32      ((port (or (and
33                  (opera:option-present :port options)
34                  (parse-integer (opera:option-argument :port options) :junk-allowed t))
35              25004)))
36      (setf candle:*job-system*
37       (if (opera:option-present :system options)
38        (intern (string-upcase (opera:option-argument :system options)) :keyword)
39        :local))
40      (let
41       ((*error-output* (make-broadcast-stream)))
42       (case candle:*job-system*
43        (:aws (asdf:load-system :candle-aws))
44        (:local (asdf:load-system :candle-local))))
45      (setf candle:*candle-dir*
46       (if (opera:option-present :dir options)
47        (opera:option-argument :dir options)
48        "/opt/candle/"))
49      (candle:server port nil))))))