Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tramp support #36

Merged
merged 8 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Changelog.org
Original file line number Diff line number Diff line change
@@ -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

Expand Down
3 changes: 2 additions & 1 deletion README.org
Original file line number Diff line number Diff line change
Expand Up @@ -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]]

Expand Down
64 changes: 33 additions & 31 deletions justl.el
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -76,6 +76,7 @@
(require 'compile)
(require 'comint)
(require 'subr-x)
(require 'tramp)

(defgroup justl nil
"Justfile customization group."
Expand Down Expand Up @@ -181,7 +182,7 @@
(read-only-mode nil))))


(defun justl--traverse-upwards (fn &optional path)

Check warning on line 185 in justl.el

View workflow job for this annotation

GitHub Actions / check (release-snapshot, false)

docstring has wrong usage of unescaped single quotes (use \= or different quoting)

Check warning on line 185 in justl.el

View workflow job for this annotation

GitHub Actions / check (29.1, false)

docstring has wrong usage of unescaped single quotes (use \= or different quoting)
"Traverse up as long as FN return nil, starting at PATH.

Variant of f.el's 'f-traverse-upwards but returns justfiles."
Expand All @@ -207,7 +208,7 @@
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)))))
Expand Down Expand Up @@ -407,7 +408,7 @@
(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."
Expand All @@ -427,7 +428,7 @@
: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."
Expand Down Expand Up @@ -462,20 +463,20 @@
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."
Expand All @@ -486,10 +487,10 @@
"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)
Expand All @@ -501,31 +502,29 @@
(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)))

(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."
Expand Down Expand Up @@ -736,6 +735,9 @@
(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))
Expand All @@ -745,7 +747,7 @@
(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)
Expand Down
11 changes: 11 additions & 0 deletions test/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions test/README.org
Original file line number Diff line number Diff line change
@@ -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
11 changes: 7 additions & 4 deletions test/justl-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -257,23 +257,26 @@
(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)."
(justl--exec-without-justfile "just" (list "plan_non_existent"))
(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)."
(justl--exec-without-justfile "just" (list "push2" "ver1" "ver2"))
(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--**")

Expand Down
Loading