Commits

David Krentzlin  committed 99a34fe

restructured commands so that they're added to their processors after initialization

  • Participants
  • Parent commits d2d5e6f

Comments (0)

Files changed (1)

File mira.core/src/processor.lisp

   (gethash (sring-downcase (string name)) collection))
 
 ;;
-;; (defcommand processor 0 (echo (content &key (foo  1))
+;; (defcommand <processor-echo> 0 (echo (content &key (foo  1))
 ;;                           (do-sth-with content)))))
 
-;; (defusage processor echo
+;; (defusage <processor-echo> echo
 ;;   :banner "echo content"
 ;;   (foo :required "Sets the frooble")
 ;;   (bar :optional "Set the barble")
     `(labels ((,closure (lambda (&rest arguments)
                           (destructuring-bind (,@command-lambda-list) arguments
                             ,@body))))
-       (add-command ,proc
-                    (string ',command-name)
-                    (make-instance '<command>
-                                   :required-access-level ,level
-                                   :body ,closure)))))
+       (defmethod initialize-instance :after ((processor  ,proc) &rest args)
+         (declare (ignore args))
+         (add-command processor
+                      (string ',command-name)
+                      (make-instance '<command>
+                                     :required-access-level ,level
+                                     :body ,closure))))))
 
 @export
 (defmacro defusage (processor command-name banner &rest options)
-  `(with-slots (usage help) ,processor
-     (setf usage banner)
-     (setf help (generate-help
-                 (string ',command-name)
-                 banner
-                 '(,@options)))))
+  `(defmethod add-command :after ((processor ,processor) cmd-name cmd)
+     (when (equal? (string ',command-name) (string cmd-name))
+       (with-slots (usage help) ,cmd
+         (setf usage banner)
+         (setf help (generate-help
+                     (string ',command-name)
+                     banner
+                     '(,@options)))))))
 
 (defun command-syntax? (input self-ident)
   (cl-ppcre:scan (format nil "^~A:? +~A(.+?)"