+ ((eql error :unknown-option)
+ (format *error-output* "Unknown option: ~A. See 'candle project --help'.~%" (car remaining-args)))
+ ((eql error :required-argument-missing)
+ (format *error-output* "Missing argument for ~A. See 'candle project --help'.~%" (car remaining-args)))
+ ((opera:option-present :help options) (project-usage))
+ (t
+ (let
+ ((subcommand (intern (string-upcase (car remaining-args)) :keyword)))
+ (case subcommand
+ (:delete (delete-project (cdr remaining-args)))
+ (:add (add-project (cdr remaining-args)))
+ (:show (show-project (cdr remaining-args)))
+ (:refresh (refresh-project (cdr remaining-args)))
+ (t (project-usage))))))))
+
+(defun project-usage ()
+ (format t "~A"
+ (opera:usage
+ "candle project"
+ (project-options)
+ "Interacts with projects. The available project subcommands are:
+ add Add a project
+ delete Delete a project
+ show Show project branch information
+ refresh Tell the candle server to refresh the project information")))
+
+(defun project-options ()
+ '((:name :help :short "h" :long "help" :description "Print this usage.")
+ (:positional "<subcommand>" :description "Project subcommand, see below.")))
+
+; (:name :show :long "show" :takes-argument t :description
+; "Show branch information for a project named by NAME."
+; :variable-name "NAME")
+; (:name :refresh :long "refresh" :takes-argument t :description
+; "Refresh project named by NAME."
+; :variable-name "NAME")
+; (:name :delete :long "delete" :takes-argument t :description
+; "Delete a project named by NAME."
+; :variable-name "NAME")
+
+(defun add-project (args)
+ (let*
+ ((options
+ '((:name :help :short "h" :long "help" :description "Print this usage.")
+ (:positional "<name>:<src>" :description "<name> is the name of the project, which must be alphanumeric (hyphens are allowed), while <src> is the location of the repository for cloning. This location must be accessible by the machine running candle.")))
+ (usage (opera:usage "candle project add" options)))
+ (multiple-value-bind (options remaining-args error) (opera:process-arguments options args)
+ (cond
+ ((eql error :unknown-option) (format *error-output* "Unknown option: ~A. See 'candle project add --help'.~%" (car remaining-args)))
+ ((eql error :required-argument-missing) (format *error-output* "Missing argument for ~A. See 'candle project add --help'.~%" (car remaining-args)))
+ ((opera:option-present :help options) (format t "~A" usage))
+ ((not remaining-args) (format *error-output* "Required <name>:<src>. See 'candle project add --help'.~%"))
+ (t
+ (let*
+ ((project-definition (car remaining-args))
+ (pos (position #\: project-definition)))
+ (cond
+ ((not pos) (format *error-output* "Project definition ~A is not valid. See 'candle project --help'.~%" project-definition))
+ (t
+ (let*
+ ((name (subseq project-definition 0 pos))
+ (src (subseq project-definition (1+ pos))))
+ (communication:query `(candle:add-project ,name ,src))
+ (format t "Added project ~A at src definition ~A~%" name src))))))))))
+
+(defun delete-project (args)
+ (let*
+ ((options
+ '((:name :help :short "h" :long "help" :description "Print this usage.")
+ (:positional "<name>" :description "<name> is the name of the project to delete")))
+ (usage (opera:usage "candle project delete" options)))
+ (multiple-value-bind (options remaining-args error) (opera:process-arguments options args)
+ (cond
+ ((eql error :unknown-option) (format *error-output* "Unknown option: ~A. See 'candle project delete --help'.~%" (car remaining-args)))
+ ((eql error :required-argument-missing) (format *error-output* "Missing argument for ~A. See 'candle project delete --help'.~%" (car remaining-args)))
+ ((opera:option-present :help options) (format t "~A" usage))
+ ((not remaining-args) (format *error-output* "Required <name>. See 'candle project delete --help'.~%"))
+ (t
+ (communication:query `(candle:delete-project ,(car remaining-args)))
+ (format t "Removed project ~A~%" (car remaining-args)))))))
+
+(defun show-project (args)
+ (let*
+ ((options
+ '((:name :help :short "h" :long "help" :description "Print this usage.")
+ (:positional "<name>" :description "<name> is the name of the project to show")))
+ (usage (opera:usage "candle project delete" options)))
+ (multiple-value-bind (options remaining-args error) (opera:process-arguments options args)
+ (cond
+ ((eql error :unknown-option) (format *error-output* "Unknown option: ~A. See 'candle project show --help'.~%" (car remaining-args)))
+ ((eql error :required-argument-missing) (format *error-output* "Missing argument for ~A. See 'candle project show --help'.~%" (car remaining-args)))
+ ((opera:option-present :help options) (format t "~A" usage))
+ ((not remaining-args) (format *error-output* "Required <name>. See 'candle project show --help'.~%"))
+ (t
+ (let*
+ ((branch-infos (communication:query `(candle:project-branch-information ,(car remaining-args))))
+ (width (apply #'max (mapcar #'length (mapcar #'car branch-infos)))))
+ (mapcar
+ (lambda (branch-info)
+ (format t (format nil "~~~A@A: ~~A~~%" width)
+ (first branch-info)
+ (job-info->line (second branch-info))))
+ (sort branch-infos #'< :key (lambda (branch-info) (third (second branch-info)))))))))))
+
+(defun refresh-project (args)
+ (let*
+ ((options
+ '((:name :help :short "h" :long "help" :description "Print this usage.")
+ (:positional "<name>" :description "<name> is the name of the project to refresh")))
+ (usage (opera:usage "candle project refresh" options)))
+ (multiple-value-bind (options remaining-args error) (opera:process-arguments options args)
+ (cond
+ ((eql error :unknown-option) (format *error-output* "Unknown option: ~A. See 'candle project refresh --help'.~%" (car remaining-args)))
+ ((eql error :required-argument-missing) (format *error-output* "Missing argument for ~A. See 'candle project refresh --help'.~%" (car remaining-args)))
+ ((opera:option-present :help options) (format t "~A" usage))
+ ((not remaining-args) (format *error-output* "Required <name>. See 'candle project refresh --help'.~%"))
+ (t
+ (communication:query `(candle:refresh-project ,(car remaining-args)))
+ (format t "Refreshed project ~A~%" (car remaining-args)))))))
+
+;;; Section for ./candle job