Add environments for running
[candle] / src / main / cli.lisp
index 1fff398fd28aabb595e8c495be6e78e5ba71c58d..697fb42a5e333e9b04e7fe7dff09ecfdede4b60f 100644 (file)
 
 (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")
+      (:name :env :long "env" :variable-name "ENV" :takes-argument t
+       :description "Runs candle with *candle-environment* set to ENV as a keyword."))))
+  (standard-cli "candle run" options args :default nil
+   (when (opera:option-present :env parsed-options)
+    (setf candle:*environment* (intern (string-upcase (opera:option-argument :env parsed-options)) :keyword)))
+   (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)))))))