From d7f08bad7f5d32edb80f2e1468eff32c50166a94 Mon Sep 17 00:00:00 2001 From: Frank Duncan Date: Sat, 18 Dec 2021 11:09:07 -0600 Subject: [PATCH] Move server cli into repository with its own file --- bin/candle-server | 49 +--------------------------------------- candle.asd | 3 ++- src/main/package.lisp | 1 + src/main/server-cli.lisp | 48 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 49 deletions(-) create mode 100644 src/main/server-cli.lisp diff --git a/bin/candle-server b/bin/candle-server index 60a847c..5a14859 100755 --- a/bin/candle-server +++ b/bin/candle-server @@ -8,53 +8,6 @@ ((*error-output* (make-broadcast-stream))) (asdf:load-system :candle)) -(defpackage #:candle-server-cli (:use #:common-lisp)) -(in-package #:candle-server-cli) - -(defvar *options* - '((:name :help :short "h" :long "help" :description "Print this usage.") - (:name :port :short "p" :long "port" :takes-argument t :variable-name "PORT" - :description "Port on which to listen for commands. Defaults to 25004") - (:name :dir :long "candle-dir" :takes-argument t :variable-name "DIR" - :description "Directory for candle related data. Will be created if does not exist. Defaults to /opt/candle/") - (:name :system :long "system" :takes-argument t :variable-name "SYSTEM" - :description "System on which to run jobs. Currently available are local and aws. Defaults to local."))) - -(defun usage () - (format t "~A" - (opera:usage - "candle-server" - *options* - "Starts a candle continuous integration server. Use 'candle' to interact with the server."))) - -(multiple-value-bind (options remaining-args error) (opera:process-arguments *options* (cdr sb-ext:*posix-argv*)) - (cond - ((opera:option-present :help options) (usage)) - (remaining-args - (format *error-output* "Don't understand ~A. See 'candle-server -h'~%" (car remaining-args)) - (sb-ext:exit :code 1)) - ((and (opera:option-present :port options) (not (parse-integer (opera:option-argument :port options) :junk-allowed t))) - (format *error-output* "--port requires a number. See 'candle-server -h'~%")) - (t - (let - ((port (or (and - (opera:option-present :port options) - (parse-integer (opera:option-argument :port options) :junk-allowed t)) - 25004))) - (setf candle:*job-system* - (if (opera:option-present :system options) - (intern (string-upcase (opera:option-argument :system options)) :keyword) - :local)) - (let - ((*error-output* (make-broadcast-stream))) - (case candle:*job-system* - (:aws (asdf:load-system :candle-aws)) - (:local (asdf:load-system :candle-local)))) - (setf candle:*candle-dir* - (if (opera:option-present :dir options) - (opera:option-argument :dir options) - "/opt/candle/")) - (format t "Starting server on port ~A~%" port) - (candle:server port nil))))) +(candle-server-cli:run) ; vim:ft=lisp diff --git a/candle.asd b/candle.asd index 30a6da3..77493d2 100644 --- a/candle.asd +++ b/candle.asd @@ -11,7 +11,8 @@ (:file "run") (:file "processor") (:file "server") - (:file "cli")) + (:file "cli") + (:file "server-cli")) :depends-on (:herbie-utility :opera)) (asdf:defsystem candle-aws diff --git a/src/main/package.lisp b/src/main/package.lisp index 9d04cea..7545b28 100644 --- a/src/main/package.lisp +++ b/src/main/package.lisp @@ -8,5 +8,6 @@ #:candle-error #:candle-error-reason)) (defpackage #:candle-cli (:use :cl) (:export :run)) +(defpackage #:candle-server-cli (:use :cl) (:export :run)) (defpackage #:candle-aws (:use :cl)) (defpackage #:candle-local (:use :cl)) diff --git a/src/main/server-cli.lisp b/src/main/server-cli.lisp new file mode 100644 index 0000000..8947727 --- /dev/null +++ b/src/main/server-cli.lisp @@ -0,0 +1,48 @@ +(in-package #:candle-server-cli) + +(defvar *options* + '((:name :help :short "h" :long "help" :description "Print this usage.") + (:name :port :short "p" :long "port" :takes-argument t :variable-name "PORT" + :description "Port on which to listen for commands. Defaults to 25004") + (:name :dir :long "candle-dir" :takes-argument t :variable-name "DIR" + :description "Directory for candle related data. Will be created if does not exist. Defaults to /opt/candle/") + (:name :system :long "system" :takes-argument t :variable-name "SYSTEM" + :description "System on which to run jobs. Currently available are local and aws. Defaults to local."))) + +(defun usage () + (format t "~A" + (opera:usage + "candle-server" + *options* + "Starts a candle continuous integration server. Use 'candle' to interact with the server."))) + +(defun run () + (multiple-value-bind (options remaining-args error) (opera:process-arguments *options* (cdr sb-ext:*posix-argv*)) + (cond + ((opera:option-present :help options) (usage)) + (remaining-args + (format *error-output* "Don't understand ~A. See 'candle-server -h'~%" (car remaining-args)) + (sb-ext:exit :code 1)) + ((and (opera:option-present :port options) (not (parse-integer (opera:option-argument :port options) :junk-allowed t))) + (format *error-output* "--port requires a number. See 'candle-server -h'~%")) + (t + (let + ((port (or (and + (opera:option-present :port options) + (parse-integer (opera:option-argument :port options) :junk-allowed t)) + 25004))) + (setf candle:*job-system* + (if (opera:option-present :system options) + (intern (string-upcase (opera:option-argument :system options)) :keyword) + :local)) + (let + ((*error-output* (make-broadcast-stream))) + (case candle:*job-system* + (:aws (asdf:load-system :candle-aws)) + (:local (asdf:load-system :candle-local)))) + (setf candle:*candle-dir* + (if (opera:option-present :dir options) + (opera:option-argument :dir options) + "/opt/candle/")) + (format t "Starting server on port ~A~%" port) + (candle:server port nil)))))) -- 2.25.1