b0c378b875da9e709fc4eebd05032d01ae426596
[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 (opera:option-present :port options) (not (parse-integer (opera:option-argument :port options) :junk-allowed t)))
27     (format *error-output* "--port requires a number.  See 'candle-server -h'~%"))
28    (t
29     (let
30      ((port (or (and
31                  (opera:option-present :port options)
32                  (parse-integer (opera:option-argument :port options) :junk-allowed t))
33              25004)))
34     (setf candle:*job-system*
35      (if (opera:option-present :system options)
36       (intern (string-upcase (opera:option-argument :system options)) :keyword)
37       :local))
38     (let
39      ((*error-output* (make-broadcast-stream)))
40      (case candle:*job-system*
41       (:aws (asdf:load-system :candle-aws))
42       (:local (asdf:load-system :candle-local))))
43     (setf candle:*candle-dir*
44      (if (opera:option-present :dir options)
45       (opera:option-argument :dir options)
46       "/opt/candle/"))
47     (candle:server port nil))))))