Add aws processor, refactor processing a little
[candle] / bin / candle-server
1 #!/usr/bin/sbcl --script
2   
3 (setf *compile-print* nil)
4 (require 'asdf)
5 (asdf:initialize-source-registry
6  `(:source-registry (:tree ,(car (directory "."))) :INHERIT-CONFIGURATION))
7 (let
8  ((*error-output* (make-broadcast-stream)))
9  (asdf:load-system :candle))
10 (asdf:load-system :opera)
11
12 (defpackage #:candle-server-cli (:use #:common-lisp))
13 (in-package #:candle-server-cli)
14
15 (defvar *options*
16  '((:name :help :short "h" :long "help" :description "Print this usage.")
17    (:name :port :short "p" :long "port" :takes-argument t :variable-name "PORT"
18     :description "Port on which to listen for commands.  Defaults to 25004")
19    (:name :dir :long "candle-dir" :takes-argument t :variable-name "DIR"
20     :description "Directory for candle related data.  Will be created if does not exist.  Defaults to /opt/candle/")
21    (:name :system :long "system" :takes-argument t :variable-name "SYSTEM"
22     :description "System on which to run jobs.  Currently available are local and aws.  Defaults to local.")))
23
24 (defun usage ()
25  (format t "~A"
26   (opera:usage
27    "candle-server"
28    *options*
29    "Starts a candle continuous integration server.  Use 'candle' to interact with the server.")))
30
31 (multiple-value-bind (options remaining-args error) (opera:process-arguments *options* (cdr sb-ext:*posix-argv*))
32  (cond
33   ((opera:option-present :help options) (usage))
34   (remaining-args
35    (format *error-output* "Don't understand ~A.  See 'candle-server -h'~%" (car remaining-args))
36    (sb-ext:exit :code 1))
37   ((and (opera:option-present :port options) (not (parse-integer (opera:option-argument :port options) :junk-allowed t)))
38    (format *error-output* "--port requires a number.  See 'candle-server -h'~%"))
39   (t
40    (let
41     ((port (or (and
42                 (opera:option-present :port options)
43                 (parse-integer (opera:option-argument :port options) :junk-allowed t))
44             25004)))
45    (setf candle:*job-system*
46     (if (opera:option-present :system options)
47      (intern (string-upcase (opera:option-argument :system options)) :keyword)
48      :local))
49    (case candle:*job-system*
50     (:aws (asdf:load-system :candle-aws))
51     (:local (asdf:load-system :candle-local)))
52    (setf candle:*candle-dir*
53     (if (opera:option-present :dir options)
54      (opera:option-argument :dir options)
55      "/opt/candle/"))
56    (format t "Starting server on port ~A~%" port)
57    (candle:server port nil)))))
58
59 ; vim:ft=lisp