emacs-pe / docker-tramp.el

TRAMP integration for docker containers
340 stars 25 forks source link

error on using function docker-tramp--running-containers #18

Closed stardiviner closed 6 years ago

stardiviner commented 6 years ago

I try to write a helper function like this:

(defun docker-tramp-insert-running-container (container)
  "A helper function to insert the running `CONTAINER' name.
For Org-babel header argument :dir /docker:<name>:."
  (interactive)
  ;; FIXME:
  (let ((containers (docker-tramp--running-containers)))
    (insert
     (completing-read "Docker container name: "
                      containers)))
  )

But I got an error "wrong number argument".

marsam commented 6 years ago

Hi, sorry for the late response, your function requires an argument and the interactive declaration does not define that argument, you can rewrite you function as:

@@ -1,10 +1,7 @@
 (defun docker-tramp-insert-running-container (container)
   "A helper function to insert the running `CONTAINER' name.
 For Org-babel header argument :dir /docker:<name>:."
-  (interactive)
+  (interactive (let ((containers (docker-tramp--running-containers)))
+                 (list (completing-read "Docker container name: " containers))))
   ;; FIXME:
-  (let ((containers (docker-tramp--running-containers)))
-    (insert
-     (completing-read "Docker container name: "
-                      containers)))
   )

Also, remember docker-tramp--running-containers return a list of the form (ID NAME):

'(("24dbb476cdd8"  "container_name")
  ("bbd4f62e9f1d"  "other_name"))

I think completing-read will recognize it as collection, but if you want to use the container names, you need to use (mapcar 'cdr (docker-tramp--running-containers))

stardiviner commented 6 years ago

Thanks a lot.