1 #!/usr/bin/sbcl --script
3 (setf *compile-print* nil)
5 (asdf:initialize-source-registry
6 `(:source-registry (:tree ,(car (directory "."))) :INHERIT-CONFIGURATION))
7 (asdf:load-system :candle)
8 (asdf:load-system :opera)
12 (defun main-options ()
13 '((:name :help :short "h" :long "help" :description "Print this usage.")
14 (:name :port :short "p" :long "port" :takes-argument t :variable-name "PORT"
15 :description "Port on which to listen for commands. Defaults to 25004")
16 (:positional "<command>" :required t :description "Command to send to candle server")))
18 (defun project-options()
19 '((:name :help :short "h" :long "help" :description "Print this usage.")
20 (:name :add :long "add" :takes-argument t :description
21 "Add a project. <name> is the name of the project, which must not include colons, while <src> is the location of the repository for cloning. This location must be accessible by the machine running candle."
22 :variable-name "<name>:<src>")))
29 "Interacts with candle server. The available commands are:
30 project List, show or add projects
31 job List or show jobs")))
33 (defgeneric execute-command (command args))
35 (defmethod execute-command (command args)
36 (format *error-output* "Unknown command '~(~A~)'. See 'candle --help'.~%" command))
38 (defun add-project (project-definition)
40 ((pos (position #\: project-definition)))
42 ((not pos) (format *error-output* "Project definition ~A is not valid. See 'candle project --help'.~%" project-definition))
45 ((response (communication:query `(add-project ,(subseq project-definition 0 pos) ,(subseq project-definition (1+ pos))))))
46 (format t "Add project ~A at src definition ~A~%" (project-name response) (project-src response)))))))
48 (defmethod execute-command ((command (eql :project)) args)
49 (multiple-value-bind (options remaining-args error) (opera:process-arguments (project-options) args)
51 ((eql error :unknown-option) (format *error-output* "Unknown option: ~A. See 'candle project --help'.~%" (car remaining-args)))
52 ((eql error :required-argument-missing) (format *error-output* "Missing argument for ~A. See 'candle project --help'.~%" (car remaining-args)))
53 ((opera:option-present :help options) (format t "~A" (opera:usage "candle project" (project-options))))
54 ((opera:option-present :add options) (add-project (opera:option-argument :add options))))))
56 (defmethod execute-command ((command (eql :job)) args)
57 (format t "~A~%" (communication:query '(+ 2 2))))
59 (multiple-value-bind (options remaining-args error) (opera:process-arguments (main-options) (cdr sb-ext:*posix-argv*))
61 ((opera:option-present :help options) (main-usage))
62 ((eql error :unknown-option) (format *error-output* "Unknown option: ~A. See 'candle --help'.~%" (car remaining-args)))
63 ((and (opera:option-present :port options) (not (parse-integer (opera:option-argument :port options) :junk-allowed t)))
64 (format *error-output* "--port requires a number. See 'candle-server -h'~%"))
65 ((not remaining-args) (format *error-output* "Command required. See 'candle --help'.~%"))
68 ((communication:*query-port*
71 (opera:option-present :port options)
72 (parse-integer (opera:option-argument :port options) :junk-allowed t))
74 (execute-command (intern (string-upcase (car remaining-args)) :keyword) (cdr remaining-args))))))