Skip to content

Commit

Permalink
Merge pull request #60 from psibi/recipe
Browse files Browse the repository at this point in the history
Fixes a bug with non display of private recipe
  • Loading branch information
psibi authored Nov 15, 2024
2 parents a46b954 + 1cbce95 commit d5ff9ab
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 21 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ jobs:
- uses: cask/setup-cask@v1
with:
version: 0.9.0
- uses: leotaku/[email protected]
with:
file: "justl.el"
check: melpa
ignore_warnings: ${{ matrix.ignore_warnings }}
warnings_as_errors: false
- name: Run tests
run: |
emacs --version
Expand Down
7 changes: 5 additions & 2 deletions Changelog.org
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
* Unreleased

- Fix a bug with non display of private recipe.
- Make the default of ~justl-include-private-recipes~ to nil to match
with just behaviour.
- Kill process if it's still running before starting a new one in the same
buffer.
- Bugfix: Use the buffer's last command for recompile, not the last one across
all buffers.
- Bugfix: Use the buffer's last command for recompile, not the last
one across all buffers.

* 0.14

Expand Down
4 changes: 3 additions & 1 deletion README.org
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ W => open a shell without executing
change the /justl-executable/ variable to set any explicit path.
- You can also control the width of the RECIPE column in the justl
buffer via /justl-recipe width/. By default it has a value of 20.
- You can change the shell between /eshell/ and /vterm/ using the /justl-shell/ variable. Using vterm requires [[https://github.com/akermu/emacs-libvterm][the vterm package]] to be installed.
- You can change the shell between /eshell/ and /vterm/ using the
/justl-shell/ variable. Using vterm requires [[https://github.com/akermu/emacs-libvterm][the vterm package]] to be
installed.

* Future

Expand Down
52 changes: 41 additions & 11 deletions justl.el
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@
;; You can also control the width of the RECIPE column in the justl
;; buffer via `justl-recipe width`. By default it has a value of 20.
;;
;; You can change the shell between `eshell' and `vterm' using the `justl-shell'
;; variable. Using vterm requires the `vterm' package to be installed.
;; You can change the shell between `eshell' and `vterm' using the
;; `justl-shell' variable. Using vterm requires the `vterm' package to
;; be installed.
;;

;;; Code:
Expand Down Expand Up @@ -92,10 +93,12 @@
(defcustom justl-executable "just"
"Location of just executable."
:type 'file
:group 'justl
:safe 'stringp)

(defcustom justl-recipe-width 20
"Width of the recipe column."
:group 'justl
:type 'integer)

(defcustom justl-justfile nil
Expand All @@ -104,25 +107,30 @@
If this is NIL, it means that no justfile was found. In any
other cases, it's a known path."
:type 'string
:group 'justl
:local t
:safe 'stringp)

(defcustom justl-include-private-recipes t
(defcustom justl-include-private-recipes nil
"If non-nil, include private recipes in the list."
:type 'boolean
:group 'justl
:safe 'booleanp)

(defcustom justl-per-recipe-buffer nil
"If non-nil, create a new buffer per recipe."
:type 'boolean
:group 'justl
:safe 'booleanp)

(defcustom justl-shell 'eshell
"Shell to use when running recipes.
Can be either Eshell or vterm. Using vterm requires the vterm package to
be installed."
Can be either Eshell or vterm. Using vterm requires the vterm
package to be installed."

:type '(choice (const eshell)
(const vterm)))
(const vterm))
:group 'justl)

(defun justl--recipe-output-buffer (recipe-name)
"Return the buffer name for the RECIPE-NAME."
Expand Down Expand Up @@ -412,27 +420,49 @@ Logs the command run."
(cdr recipes-entry)))
parsed)))))

(cl-defstruct recipe
;; Recipe name
name
;; Optional recipe documentation
doc
;; Parameters for the recipe
parameters
;; Is the recipe private
private)

(defun justl--get-recipes (justfile)
"Return all the recipes from JUSTFILE.
They are returned as objects, as per the JSON output of \"just --dump\"."
(let-alist (justl--parse justfile)
(mapcar 'cdr .recipes)))
(mapcar (lambda (x) (make-recipe :name (alist-get 'name x)
:doc (alist-get 'doc x)
:parameters (alist-get 'parameters x)
:private (alist-get 'private x))) .recipes)))

;;; todo: For easily integrating it, we need something like this
;;; integrated upstream:
;;; https://github.com/casey/just/issues/2252#issuecomment-2474171211
(defun justl--get-modules (justfile)
"Return all the modules from JUSTFILE.
They are returned as objects, as per the JSON output of \"just --dump\"."
(let-alist (justl--parse justfile)
(mapcar 'car .modules)))

(defun justl--recipe-name (recipe)
"Get the name of RECIPE."
(let-alist recipe .name))
(recipe-name recipe))

(defun justl--recipe-desc (recipe)
"Get the description of RECIPE."
(let-alist recipe .doc))
(recipe-doc recipe))

(defun justl--recipe-args (recipe)
"Get the arguments for RECIPE."
(let-alist recipe .parameters))
(recipe-parameters recipe))

(defun justl--recipe-private-p (recipe)
"Return non-nil if RECIPE is private."
(let-alist recipe (cl-find "private" .attributes :test 'string=)))
(recipe-private recipe))

(defun justl--arg-name (arg)
"Get the name of argument ARG."
Expand Down
4 changes: 4 additions & 0 deletions test/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ carriage-return:
color:
#!/usr/bin/env bash
printf "\x1B[31mThis is red text\n"
# private recipe
_private:
echo private
15 changes: 14 additions & 1 deletion test/justl-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

(ert-deftest justl--get-recipes-test ()
(should (equal
(list "default" "build-cmd" "plan" "push" "push2" "fail" "carriage-return" "color")
(list "default" "build-cmd" "plan" "push" "push2" "fail" "carriage-return" "color" "_private")
(mapcar 'justl--recipe-name (justl--get-recipes "./justfile")))))

(ert-deftest justl--get-description-test ()
Expand Down Expand Up @@ -158,6 +158,19 @@
(kill-buffer "*just-plan*")
(customize-set-variable 'justl-per-recipe-buffer current)))

(ert-deftest justl--no-private-recipe-by-default ()
(justl)
(with-current-buffer (justl--buffer-name)
(let ((buf-string (buffer-substring-no-properties (point-min) (point-max))))
(should-not (s-contains? "_private" buf-string)))))

(ert-deftest justl--private-recipe-visible ()
(let ((justl-include-private-recipes t))
(justl))
(with-current-buffer (justl--buffer-name)
(let ((buf-string (buffer-substring-no-properties (point-min) (point-max))))
(should (s-contains? "_private" buf-string)))))

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

(provide 'justl-test)
Expand Down

0 comments on commit d5ff9ab

Please sign in to comment.