Skip to content

Commit

Permalink
Merge pull request #35 from psibi/30-with-args
Browse files Browse the repository at this point in the history
justl-exec-recipe-in-dir now prompts for args when needed
  • Loading branch information
psibi authored Aug 6, 2023
2 parents e4cb490 + 43c7b8a commit 537323a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Changelog.org
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
* Unreleased

- justl-exec-recipe-in-dir prompts for arguments when needed. Fixes
[[https://github.com/psibi/justl.el/issues/30][issue 30]].

* 0.12

- Add unstable flag to transient.
Expand Down
16 changes: 13 additions & 3 deletions justl.el
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,19 @@ and output of process."
(defun justl-exec-recipe-in-dir ()
"Populate and execute the selected recipe."
(interactive)
(let* ((recipies (completing-read "Recipies: " (justl--get-recipies)
nil nil nil nil "default")))
(justl--exec-without-justfile justl-executable (list recipies))))
(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)))))

(defun justl-exec-default-recipe ()
"Execute default recipe."
Expand Down
24 changes: 24 additions & 0 deletions test/justl-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,30 @@
(should (s-contains? "Available recipes:\n" buf-string))))
(kill-buffer justl--output-process-buffer))

(ert-deftest justl--execute-interactive-recipe ()
"Checks justl-exec-recipe-in-dir indirectly (success case)."
(justl--exec-without-justfile "just" (list "plan"))
(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)))))

(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)))))

(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)))))

;; (ert "justl--**")

(provide 'justl-test)
Expand Down

0 comments on commit 537323a

Please sign in to comment.