From 5c21748c18e32bb9fe17bb4c23329be02edc23a2 Mon Sep 17 00:00:00 2001 From: Frank Duncan Date: Sun, 26 Dec 2021 16:58:28 -0600 Subject: [PATCH] Add specifying task to candle run --- src/main/cli.lisp | 17 ++++++++++++++--- src/main/package.lisp | 2 +- src/main/run.lisp | 35 +++++++++++++++++++++++++++++++---- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/src/main/cli.lisp b/src/main/cli.lisp index 1fff398..75ecd40 100644 --- a/src/main/cli.lisp +++ b/src/main/cli.lisp @@ -269,6 +269,17 @@ (defmethod execute-command ((command (eql :run)) args) (let - ((options '((:name :help :short "h" :long "help" :description "Print this usage.")))) - (standard-cli "run" options args :default nil - (when (not (candle:run)) (sb-ext:exit :code 1))))) + ((options + '((:name :help :short "h" :long "help" :description "Print this usage.") + (:name :task :long "task" :variable-name "TASK" :takes-argument t :description "Run TASK")))) + (standard-cli "candle run" options args :default nil + (cond + ((opera:option-present :task parsed-options) + (let + ((tasks (candle:list-tasks)) + (specified-task (intern (string-upcase (opera:option-argument :task parsed-options)) :keyword))) + (if + (not (find specified-task (candle:list-tasks))) + (error-and-exit "Task ~(~A~) does not exist in .candle file" specified-task) + (candle:run specified-task)))) + (t (when (not (candle:run)) (sb-ext:exit :code 1))))))) diff --git a/src/main/package.lisp b/src/main/package.lisp index 6365450..fe0bc70 100644 --- a/src/main/package.lisp +++ b/src/main/package.lisp @@ -1,7 +1,7 @@ (defpackage #:candle (:use :cl) (:export #:server #:add-project #:delete-project #:refresh-project #:list-projects - #:project-branch-information #:run #:*candle-dir* #:*job-system* #:*candle-dir* #:failures + #:project-branch-information #:run #:list-tasks #:*candle-dir* #:*job-system* #:*candle-dir* #:failures #:project-job-information #:get-job-log #:retry-job #:job-project #:project-dir #:process-job-in-system #:shutdown-system diff --git a/src/main/run.lisp b/src/main/run.lisp index d979735..659beed 100644 --- a/src/main/run.lisp +++ b/src/main/run.lisp @@ -10,17 +10,40 @@ (progn (format t "~c[1;32m- ~:(~A~) Passed!~c[0m~%" #\Esc (getf task :name) #\Esc) t) (format t "~c[1;31m- ~:(~A~) Failed!~c[0m~%" #\Esc (getf task :name) #\Esc))) -(defun run () - "RUN => RESULT +(defun list-tasks () + "LIST-TASKS => TASKS + + TASKS: TASK* ARGUMENTS AND VALUES: + TASK: a keyword, representing a task that can be run + +DESCRIPTION: + + Get a list of tasks available in the current .candle file." + (if + (not (probe-file ".candle")) + :dot-candle-absent + (with-open-file (str ".candle") + (asdf:initialize-source-registry `(:source-registry (:tree ,(car (directory "."))) :INHERIT-CONFIGURATION)) + (mapcar #'import-package (cdr (read str))) + (mapcar (lambda (task) (getf task :name)) (getf (read str) :tasks))))) + +(defun run (&optional specified-task) + "RUN &optional SPECIFIED-TASK => RESULT + +ARGUMENTS AND VALUES: + + SPECIFIED-TASK: a keyword, the task to run RESULT: a boolean, whether the process was successful DESCRIPTION: Runs the script specified by the .candle file in the current directory. - When completed, the boolean will be returned if it was successful or not." + When completed, the boolean will be returned if it was successful or not. + + If SPECIFIED-TASK exists, only that task is run." (if (not (probe-file ".candle")) :dot-candle-absent @@ -30,4 +53,8 @@ DESCRIPTION: (let ((candle-definition (read str))) (format t "Running tasks for ~(~A~)~%" (getf candle-definition :name)) - (every #'identity (mapcar #'run-task (getf candle-definition :tasks))))))) + (every #'identity + (mapcar #'run-task + (remove-if + (lambda (task) (and specified-task (not (eql (getf task :name) specified-task)))) + (getf candle-definition :tasks)))))))) -- 2.25.1