X-Git-Url: https://code.consxy.com/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fcli.lisp;h=fb38f58570b0e4e47790a83ee76c4b214239bb63;hb=09ef79e902dcf475d6cd9dc34bc74a46b39150c3;hp=4b56b16a8016cec79f3f8fe5e1dd5b085c970639;hpb=71ec31971d4b7540adfb9edd507fd786e935839d;p=candle diff --git a/src/main/cli.lisp b/src/main/cli.lisp index 4b56b16..fb38f58 100644 --- a/src/main/cli.lisp +++ b/src/main/cli.lisp @@ -2,8 +2,12 @@ (defgeneric execute-command (command args)) +(defun error-and-exit (str &rest args) + (apply #'format *error-output* str args) + (sb-ext:exit :code 1)) + (defmethod execute-command (command args) - (format *error-output* "Unknown command '~(~A~)'. See 'candle --help'.~%" command)) + (error-and-exit "Unknown command '~(~A~)'. See 'candle --help'.~%" command)) (defun job-info->line (job-info) (format nil "~A (~A) ~A" @@ -23,10 +27,11 @@ ((opera:option-present :help parsed-options) (format t "~A" ,(if (eql usage :default) `(opera:usage ,cmd ,options-in) usage))) ((eql error :unknown-option) - (format *error-output* "Unknown option: ~A. See '~A --help'.~%" (car remaining-args) ,cmd)) + (error-and-exit "Unknown option: ~A. See '~A --help'.~%" (car remaining-args) ,cmd)) ((eql error :required-argument-missing) - (format *error-output* "Missing argument for ~A. See '~A --help'.~%" (car remaining-args) ,cmd)) - ((and ,remaining-args-required (not remaining-args)) (format *error-output* "~A required. See 'candle --help'.~%" ,remaining-args-required)) + (error-and-exit "Missing argument for ~A. See '~A --help'.~%" (car remaining-args) ,cmd)) + ((and ,remaining-args-required (not remaining-args)) + (error-and-exit "~A required. See 'candle --help'.~%" ,remaining-args-required)) (t ,@success)))) @@ -34,17 +39,27 @@ (defun run () (standard-cli "candle" (main-options) (cdr sb-ext:*posix-argv*) (main-usage) "Command" - (if - (and (opera:option-present :port parsed-options) (not (parse-integer (opera:option-argument :port parsed-options) :junk-allowed t))) - (format *error-output* "--port requires a number. See 'candle -h'~%") - (let - ((communication:*query-port* - (or - (and - (opera:option-present :port parsed-options) - (parse-integer (opera:option-argument :port parsed-options) :junk-allowed t)) - 25004))) - (execute-command (intern (string-upcase (car remaining-args)) :keyword) (cdr remaining-args)))))) + (handler-case + (if + (and (opera:option-present :port parsed-options) (not (parse-integer (opera:option-argument :port parsed-options) :junk-allowed t))) + (error-and-exit "--port requires a number. See 'candle -h'~%") + (let + ((communication:*query-port* + (or + (and + (opera:option-present :port parsed-options) + (parse-integer (opera:option-argument :port parsed-options) :junk-allowed t)) + 25004))) + (execute-command (intern (string-upcase (car remaining-args)) :keyword) (cdr remaining-args)))) + (candle:candle-error (e) + (case (candle:candle-error-reason e) + (:project-does-not-exist (error-and-exit "Project does not exist~%")) + (:job-does-not-exist (error-and-exit "Job does not exist~%")) + (:invalid-project-name (error-and-exit "Project name invalid~%")) + (:invalid-project-uri (error-and-exit "Project uri invalid~%")) + (:project-name-taken (error-and-exit "Project name already taken~%")) + (:project-failed-to-get-branches (error-and-exit "Unable to retrieve branches from server~%")) + (t (error-and-exit "Unknown error occurred: ~(~S~)~%" (candle:candle-error-reason e)))))))) (defun main-options () '((:name :help :short "h" :long "help" :description "Print this usage.") @@ -101,7 +116,7 @@ ((project-definition (car remaining-args)) (pos (position #\: project-definition))) (cond - ((not pos) (format *error-output* "Project definition ~A is not valid. See 'candle project add --help'.~%" project-definition)) + ((not pos) (error-and-exit "Project definition ~A is not valid. See 'candle project add --help'.~%" project-definition)) (t (let* ((name (subseq project-definition 0 pos)) @@ -165,15 +180,8 @@ (case subcommand (:list (job-list (cdr remaining-args))) (:log (job-log (cdr remaining-args))) + (:retry (retry-job (cdr remaining-args))) (t (format t "~A" (job-usage))))))) -; (multiple-value-bind (options remaining-args error) (opera:process-arguments (job-options) args) -; (cond -; ((eql error :unknown-option) (format *error-output* "Unknown option: ~A. See 'candle job --help'.~%" (car remaining-args))) -; ((eql error :required-argument-missing) (format *error-output* "Missing argument for ~A. See 'candle job --help'.~%" (car remaining-args))) -; ((opera:option-present :help options) (format t "~A" (opera:usage "candle job" (job-options) "Lists all jobs in PROJECT if no other action is specified"))) -; ((not (opera:option-present :project-name options)) (format *error-output* "Requires --project argument. See 'candle job --help'.~%" )) -; ((opera:option-present :log options) (job-log (opera:option-argument :project-name options) (opera:option-argument :log options))) -; (t (project-history (opera:option-argument :project-name options)))))) (defun job-options () '((:name :help :short "h" :long "help" :description "Print this usage.") @@ -184,8 +192,9 @@ "candle job" (project-options) "Interacts with projects. The available project subcommands are: - list List jobs - log : View the log for a job")) + list List jobs + log : View the log for a job + retry : Retry a job")) (defun job-list (args) (let @@ -216,7 +225,20 @@ (multiple-value-bind (project-name sha) (decompose-job-definition (car remaining-args)) (if project-name (format t "~A" (communication:query `(candle:get-job-log ,project-name ,sha))) - (format *error-output* "Job definition ~A is not valid. See 'candle job log --help'.~%" (car remaining-args))))))) + (error-and-exit "Job definition ~A is not valid. See 'candle job log --help'.~%" (car remaining-args))))))) + +(defun retry-job (args) + (let + ((options + '((:name :help :short "h" :long "help" :description "Print this usage.") + (:positional ":" :description " is the name of the project, while is the sha of the job in question.")))) + (standard-cli "candle job retry" options args :default ":" + (multiple-value-bind (project-name sha) (decompose-job-definition (car remaining-args)) + (if project-name + (progn + (communication:query `(candle:retry-job ,project-name ,sha)) + (format t "Retrying job ~A~%" (car remaining-args))) + (error-and-exit "Job definition ~A is not valid. See 'candle job log --help'.~%" (car remaining-args))))))) ;;; Section for ./candle run