1 (in-package #:candle-cli)
4 '((:name :help :short "h" :long "help" :description "Print this usage.")
5 (:name :port :short "p" :long "port" :takes-argument t :variable-name "PORT"
6 :description "Port on which to listen for commands. Defaults to 25004")
7 (:positional "<command>" :required t :description "Command to send to candle server")))
9 (defun project-options ()
10 '((:name :help :short "h" :long "help" :description "Print this usage.")
11 (:name :add :long "add" :takes-argument t :description
12 "Add a project. NAME is the name of the project, which must not include colons, while SRC is the location of the repository for cloning. This location must be accessible by the machine running candle."
13 :variable-name "NAME:SRC")
14 (:name :show :long "show" :takes-argument t :description
15 "Show branch information for a project named by NAME."
16 :variable-name "NAME")
17 (:name :refresh :long "refresh" :takes-argument t :description
18 "Refresh project named by NAME."
19 :variable-name "NAME")
20 (:name :history :long "history" :takes-argument t :description
21 "Show history of project named by NAME."
22 :variable-name "NAME")
23 (:name :delete :long "delete" :takes-argument t :description
24 "Delete a project named by NAME."
25 :variable-name "NAME")))
28 '((:name :help :short "h" :long "help" :description "Print this usage.")
29 (:name :project-name :long "project" :takes-argument t :description "The project name for the jobs under consideration.")))
32 '((:name :help :short "h" :long "help" :description "Print this usage.")))
39 "Interacts with candle server. The available commands are:
40 project List, show or add projects
42 run Local command. Run candle in the current working directory")))
44 (defgeneric execute-command (command args))
46 (defmethod execute-command (command args)
47 (format *error-output* "Unknown command '~(~A~)'. See 'candle --help'.~%" command))
49 (defun add-project (project-definition)
51 ((pos (position #\: project-definition)))
53 ((not pos) (format *error-output* "Project definition ~A is not valid. See 'candle project --help'.~%" project-definition))
56 ((name (subseq project-definition 0 pos))
57 (src (subseq project-definition (1+ pos))))
58 (communication:query `(candle:add-project ,name ,src))
59 (format t "Added project ~A at src definition ~A~%" name src))))))
61 (defun delete-project (name)
62 (communication:query `(candle:delete-project ,name))
63 (format t "Removed project ~A~%" name))
65 (defun job-info->line (job-info)
66 (format nil "~A (~A) ~A"
67 (subseq (first job-info) 0 8)
68 (format nil "~{~A/~A/~A ~A:~A~}"
69 (utils:time-as-list (third job-info) :month :date :year :hr :min))
70 (case (second job-info)
71 (:succeeded (format nil "~c[1;32mPassed~c[0m" #\Esc #\Esc))
72 (:failed (format nil "~c[1;31mFailed~c[0m" #\Esc #\Esc))
74 (:no-candle-file "No candle file present")
75 (:in-progress "In progress"))))
77 (defun show-project (name)
79 ((branch-infos (communication:query `(candle:project-branch-information ,name)))
80 (width (apply #'max (mapcar #'length (mapcar #'car branch-infos)))))
83 (format t (format nil "~~~A@A: ~~A~~%" width)
85 (job-info->line (second branch-info))))
86 (sort branch-infos #'< :key (lambda (branch-info) (third (second branch-info)))))))
88 (defun project-history (name)
92 (sort (communication:query `(candle:project-job-information ,name)) #'< :key #'third))))
94 (defun refresh-project (name)
95 (communication:query `(candle:refresh-project ,name))
96 (format t "Refreshed project ~A~%" name))
98 (defmethod execute-command ((command (eql :project)) args)
99 (multiple-value-bind (options remaining-args error) (opera:process-arguments (project-options) args)
101 ((eql error :unknown-option) (format *error-output* "Unknown option: ~A. See 'candle project --help'.~%" (car remaining-args)))
102 ((eql error :required-argument-missing) (format *error-output* "Missing argument for ~A. See 'candle project --help'.~%" (car remaining-args)))
103 ((opera:option-present :help options) (format t "~A" (opera:usage "candle project" (project-options))))
104 ((opera:option-present :delete options) (delete-project (opera:option-argument :delete options)))
105 ((opera:option-present :show options) (show-project (opera:option-argument :show options)))
106 ((opera:option-present :refresh options) (refresh-project (opera:option-argument :refresh options)))
107 ((opera:option-present :history options) (project-history (opera:option-argument :history options)))
108 ((opera:option-present :add options) (add-project (opera:option-argument :add options))))))
110 (defmethod execute-command ((command (eql :job)) args)
111 (multiple-value-bind (options remaining-args error) (opera:process-arguments (job-options) args)
113 ((eql error :unknown-option) (format *error-output* "Unknown option: ~A. See 'candle job --help'.~%" (car remaining-args)))
114 ((eql error :required-argument-missing) (format *error-output* "Missing argument for ~A. See 'candle job --help'.~%" (car remaining-args)))
115 ((opera:option-present :help options) (format t "~A" (opera:usage "candle job" (job-options)))))))
117 (defmethod execute-command ((command (eql :run)) args)
118 (multiple-value-bind (options remaining-args error) (opera:process-arguments (run-options) args)
120 ((eql error :unknown-option) (format *error-output* "Unknown option: ~A. See 'candle run --help'.~%" (car remaining-args)))
121 ((eql error :required-argument-missing) (format *error-output* "Missing argument for ~A. See 'candle run --help'.~%" (car remaining-args)))
122 (remaining-args (format *error-output* "Unknown option: ~A. See 'candle run --help'.~%" (car remaining-args)))
123 ((opera:option-present :help options) (format t "~A" (opera:usage "candle run" (run-options))))
124 ((not (candle:run)) (sb-ext:exit :code 1)))))
127 (multiple-value-bind (options remaining-args error) (opera:process-arguments (main-options) (cdr sb-ext:*posix-argv*))
129 ((opera:option-present :help options) (main-usage))
130 ((eql error :unknown-option) (format *error-output* "Unknown option: ~A. See 'candle --help'.~%" (car remaining-args)))
131 ((and (opera:option-present :port options) (not (parse-integer (opera:option-argument :port options) :junk-allowed t)))
132 (format *error-output* "--port requires a number. See 'candle-server -h'~%"))
133 ((not remaining-args) (format *error-output* "Command required. See 'candle --help'.~%"))
136 ((communication:*query-port*
139 (opera:option-present :port options)
140 (parse-integer (opera:option-argument :port options) :junk-allowed t))
142 (execute-command (intern (string-upcase (car remaining-args)) :keyword) (cdr remaining-args)))))))