diff --git a/Changelog.org b/Changelog.org index 15886fc..550cf3a 100644 --- a/Changelog.org +++ b/Changelog.org @@ -1,7 +1,13 @@ * Unreleased -- justl-exec-recipe-in-dir prompts for arguments when needed. Fixes +- TRAMP support +- ~justl-exec-recipe-in-dir~ prompts for arguments when needed. Fixes [[https://github.com/psibi/justl.el/issues/30][issue 30]]. +- Fix directory traversing when searching for justfiles. +- Improve error handling when a justfile is not found on different + cases. +- Add documentation on how to test it with TRAMP and docker. +- Update CI to support Emacs 29.1 * 0.12 diff --git a/README.org b/README.org index 964ab4f..b5ba00c 100644 --- a/README.org +++ b/README.org @@ -5,7 +5,8 @@ justl.el mode is a major mode for driving [[https://github.com/casey/just][justfiles]]. As compared to the [[https://melpa.org/#/just-mode][just-mode]], this mode is built for listing and executing the -recipes in the justfile via the [[https://magit.vc/manual/transient][transient]] keymaps. +recipes in the justfile via the [[https://magit.vc/manual/transient][transient]] keymaps. Also works with +[[https://www.gnu.org/software/tramp/][TRAMP]]. [[https://user-images.githubusercontent.com/737477/132949123-87387b7e-8f7d-45de-ac32-8815d9c1dc5d.png]] diff --git a/justl.el b/justl.el index 236d5fd..34414a7 100644 --- a/justl.el +++ b/justl.el @@ -24,7 +24,7 @@ ;; Keywords: just justfile tools processes ;; URL: https://github.com/psibi/justl.el ;; License: GNU General Public License >= 3 -;; Package-Requires: ((transient "0.1.0") (emacs "25.3") (s "1.2.0") (f "0.20.0")) +;; Package-Requires: ((transient "0.1.0") (emacs "27.1") (s "1.2.0") (f "0.20.0")) ;;; Commentary: @@ -76,6 +76,7 @@ (require 'compile) (require 'comint) (require 'subr-x) +(require 'tramp) (defgroup justl nil "Justfile customization group." @@ -207,7 +208,7 @@ was found." dir))) (if justfiles (car justfiles) - (let ((justfile-paths (directory-files-recursively dir "justfile"))) + (let ((justfile-paths (directory-files-recursively dir justl--justfile-regex))) (if justfile-paths (car justfile-paths) nil))))) @@ -407,7 +408,7 @@ Error matching regexes from compile.el are removed." (setq next-error-overlay-arrow-position nil)) (defun justl--exec (process-name args) - "Utility function to run commands in the proper context and namespace. + "Utility function to run commands in the proper setting. PROCESS-NAME is an identifier for the process. Default to \"just\". ARGS is a ist of arguments." @@ -427,7 +428,7 @@ ARGS is a ist of arguments." :mode mode)))) (defun justl--exec-without-justfile (process-name args) - "Utility function to run commands in the proper context and namespace. + "Utility function to run commands in the proper setting. PROCESS-NAME is an identifier for the process. Default to \"just\". ARGS is a ist of arguments." @@ -462,20 +463,20 @@ CMD is the command string to run. Returns a list with status code and output of process." (justl--log-command "just-command" cmd) (with-temp-buffer - (let ((justl-status (call-process-shell-command cmd nil t)) + (let ((justl-status (process-file-shell-command cmd nil t)) (buf-string (buffer-substring-no-properties (point-min) (point-max)))) (list justl-status buf-string)))) -(defun justl--get-recipies () - "Return all the recipies." +(defun justl--get-recipies (justfile) + "Return all the recipies from JUSTFILE." (let ((recipies (split-string (justl--exec-to-string - (format "%s --summary --unsorted" - justl-executable))))) + (format "%s --justfile=%s --summary --unsorted --color=never" + justl-executable (tramp-file-local-name justfile)))))) (mapcar #'string-trim-right recipies))) (defun justl--justfile-argument () "Provides justfile argument with the proper location." - (format "--justfile=%s" justl-justfile)) + (format "--justfile=%s" (tramp-file-local-name justl-justfile))) (defun justl--justfile-from-arg (arg) "Return justfile filepath from ARG." @@ -486,10 +487,10 @@ and output of process." "Return all the recipies in JUSTFILE with description." (let* ((t-args (transient-args 'justl-help-popup)) (recipe-status (justl--exec-to-string-with-exit-code - (format "%s %s --justfile=%s --list --unsorted" + (format "%s %s --justfile=%s --list --unsorted --color=never" justl-executable (string-join t-args " ") - justfile))) + (tramp-file-local-name justfile)))) (justl-status (nth 0 recipe-status)) (recipe-lines (split-string (nth 1 recipe-status) @@ -501,11 +502,6 @@ and output of process." (mapcar (lambda (x) (list (justl--get-recipe-name (nth 0 x)) (nth 1 x))) recipes) nil))) -(defun justl--get-jrecipies () - "Return list of JRECIPE." - (let ((recipies (justl--get-recipies))) - (mapcar #'make-justl-jrecipe recipies))) - (defun justl--list-to-jrecipe (list) "Convert a single LIST of two elements to list of JRECIPE." (make-justl-jrecipe :name (nth 0 list) :args (nth 1 list))) @@ -513,19 +509,22 @@ and output of process." (defun justl-exec-recipe-in-dir () "Populate and execute the selected recipe." (interactive) - (let* ((recipe (completing-read "Recipies: " (justl--get-recipies) - nil nil nil nil "default")) - (justl-recipe (justl--get-recipe-from-file justl-justfile recipe)) - (recipe-has-args (justl--jrecipe-has-args-p justl-recipe))) - (if recipe-has-args - (let* ((cmd-args (justl-jrecipe-args justl-recipe)) - (user-args (mapcar (lambda (arg) (read-from-minibuffer - (format "Just arg for %s:" (justl-jarg-arg arg)) - (justl--util-maybe (justl-jarg-default arg) ""))) - cmd-args))) - (justl--exec-without-justfile justl-executable - (cons (justl-jrecipe-name justl-recipe) user-args))) - (justl--exec-without-justfile justl-executable (list recipe))))) + (let* ((justfile (justl--find-justfiles default-directory))) + (if (not justfile) + (error "No justfiles found")) + (let* ((recipe (completing-read "Recipies: " (justl--get-recipies justfile) + nil nil nil nil "default")) + (justl-recipe (justl--get-recipe-from-file justfile recipe)) + (recipe-has-args (justl--jrecipe-has-args-p justl-recipe))) + (if recipe-has-args + (let* ((cmd-args (justl-jrecipe-args justl-recipe)) + (user-args (mapcar (lambda (arg) (read-from-minibuffer + (format "Just arg for %s:" (justl-jarg-arg arg)) + (justl--util-maybe (justl-jarg-default arg) ""))) + cmd-args))) + (justl--exec-without-justfile justl-executable + (cons (justl-jrecipe-name justl-recipe) user-args))) + (justl--exec-without-justfile justl-executable (list recipe)))))) (defun justl-exec-default-recipe () "Execute default recipe." @@ -736,6 +735,9 @@ tweaked further by the user." (defun justl () "Invoke the justl buffer." (interactive) + (let ((justfile (justl--find-justfiles default-directory))) + (when (null justfile) + (error "No justfiles found"))) (justl--save-line) (justl--pop-to-buffer (justl--buffer-name)) (justl-mode)) @@ -745,7 +747,7 @@ tweaked further by the user." (buffer-disable-undo) (setq truncate-lines t) (let* ((justfiles (justl--find-justfiles default-directory)) - (entries (justl--get-recipies-with-desc justfiles))) + (entries (justl--get-recipies-with-desc justfiles))) (if (or (null justfiles) (not (eq justl--list-command-exit-code 0)) ) (progn (when (null justfiles) diff --git a/test/Dockerfile b/test/Dockerfile new file mode 100644 index 0000000..79b9e3b --- /dev/null +++ b/test/Dockerfile @@ -0,0 +1,11 @@ +FROM fpco/pid1:22.04 + +RUN apt update -y && apt install -y curl + +RUN curl -sL https://github.com/casey/just/releases/download/1.14.0/just-1.14.0-x86_64-unknown-linux-musl.tar.gz | tar xz && mv just /usr/local/bin/just + +RUN mkdir /home/sibi + +WORKDIR /home/sibi + +COPY justfile /home/sibi/justfile diff --git a/test/README.org b/test/README.org new file mode 100644 index 0000000..7444e16 --- /dev/null +++ b/test/README.org @@ -0,0 +1,26 @@ +* Testing tramp + +- Create a local docker image + +#+begin_src sh +docker image build . -f Dockerfile -t just-test +#+end_src + +- Run the container: + +#+begin_src sh +docker run -it just-test bash +#+end_src + +- Now do the followin in emacs: + +#+begin_src sh +M-x docker-container +#+end_src + +Go to the container that is running and get shell access. Once you get +shell access, run the usual justl commands there: + +#+begin_src +justl-exec-recipe-in-dir +#+end_src diff --git a/test/justl-test.el b/test/justl-test.el index 589d779..373ba9f 100644 --- a/test/justl-test.el +++ b/test/justl-test.el @@ -12,7 +12,7 @@ (should (equal (list "default" "build-cmd" "plan" "push" "push2" "fail" "carriage-return" "color") - (justl--get-recipies)))) + (justl--get-recipies "./justfile")))) (ert-deftest justl--list-to-recipe-test () (should (equal @@ -257,7 +257,8 @@ (justl--wait-till-exit justl--output-process-buffer) (with-current-buffer justl--output-process-buffer (let ((buf-string (buffer-substring-no-properties (point-min) (point-max)))) - (should (s-contains? "planner" buf-string))))) + (should (s-contains? "planner" buf-string)))) + (kill-buffer justl--output-process-buffer)) (ert-deftest justl--execute-interactive-recipe-failure () "Checks justl-exec-recipe-in-dir indrectly (failure case)." @@ -265,7 +266,8 @@ (justl--wait-till-exit justl--output-process-buffer) (with-current-buffer justl--output-process-buffer (let ((buf-string (buffer-substring-no-properties (point-min) (point-max)))) - (should (s-contains? "exited abnormally" buf-string))))) + (should (s-contains? "exited abnormally" buf-string)))) + (kill-buffer justl--output-process-buffer)) (ert-deftest justl--execute-interactive-recipe-multiple-args () "Checks justl-exec-recipe-in-dir indrectly (failure case)." @@ -273,7 +275,8 @@ (justl--wait-till-exit justl--output-process-buffer) (with-current-buffer justl--output-process-buffer (let ((buf-string (buffer-substring-no-properties (point-min) (point-max)))) - (should (s-contains? "ver1" buf-string))))) + (should (s-contains? "ver1" buf-string)))) + (kill-buffer justl--output-process-buffer)) ;; (ert "justl--**")