Skip to content

Commit

Permalink
justl-exec-recipe-in-dir now prompts for args when needed
Browse files Browse the repository at this point in the history
Fixes #30
  • Loading branch information
psibi committed Aug 6, 2023
1 parent e4cb490 commit 322867a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
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 322867a

Please sign in to comment.