Add job retry
[candle] / src / main / cli.lisp
index 4b56b16a8016cec79f3f8fe5e1dd5b085c970639..fe36dfbc1c775d83220fea82694430fa6a1c2804 100644 (file)
    (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.")
   "candle job"
   (project-options)
   "Interacts with projects.  The available project subcommands are:
- list                 List jobs
- log <project>:<sha>  View the log for a job"))
+ list                   List jobs
+ log <project>:<sha>    View the log for a job
+ retry <project>:<sha>  Retry a job"))
 
 (defun job-list (args)
  (let
      (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)))))))
 
+(defun retry-job (args)
+ (let
+  ((options
+   '((:name :help :short "h" :long "help" :description "Print this usage.")
+     (:positional "<project>:<sha>" :description "<project> is the name of the project, while <sha> is the sha of the job in question."))))
+  (standard-cli "candle job retry" options args :default "<project>:<sha>"
+   (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)))
+     (format *error-output* "Job definition ~A is not valid.  See 'candle job log --help'.~%" (car remaining-args)))))))
+
 ;;; Section for ./candle run
 
 (defmethod execute-command ((command (eql :run)) args)