psibi / justl.el

Major mode for driving just files.
GNU General Public License v3.0
63 stars 12 forks source link

Handing private commands #43

Open johnhamelink opened 1 year ago

johnhamelink commented 1 year ago

Hi there,

I have a justfile that looks like this:

# Usage info
_default:
    just --list

# Build & switch to new configuration
switch:
  just _rebuild switch \
    --show-trace \
    --fallback \
    --refresh \
    --flake '.#'

[macos]
update:
    nix-channel --update darwin
    darwin-rebuild changelog

[linux]
update:
    sudo nix-channel --update
    sudo nixos-rebuild changelog

[linux]
_rebuild *args:
    sudo nixos-rebuild {{args}}

[macos]
_rebuild *args:
    darwin-rebuild {{args}}

By default, justl shows this:

Screenshot 2023-09-12 at 10 13 57

But _default and _rebuild are private tasks - if I run just --list, I see:

johnhamelink@jh-mbp nix % just --list
Available recipes:
    switch # Build & switch to new configuration
    update

I think this should be the default behaviour.

I was able to fix this by adding seq-remove to justl--parse like so:

diff --git a/justl.el b/justl.el
index 071adb7..fa07ba9 100644
--- a/justl.el
+++ b/justl.el
@@ -371,8 +371,9 @@ Logs the command run."
                         1000))))
         (let ((recipes-entry (assoc 'recipes parsed)))
           (setcdr recipes-entry
-                  (seq-sort (lambda (a b) (< (unsorted-index a) (unsorted-index b)))
-                            (cdr recipes-entry)))
+                  (seq-remove (lambda (r) (equal (alist-get 'private r) t))
+                   (seq-sort (lambda (a b) (< (unsorted-index a) (unsorted-index b)))
+                             (cdr recipes-entry))))
           parsed)))))

 (defun justl--get-recipes (justfile)

What do you think? We could use let* and instead optionally filter the list before sorting it against the index, so that previous behaviour could be preserved by enabling a feature-flag?

(Btw Sorry, I haven't had the chance to catch up on #39, I'll try to get to that this week!) fixed!

psibi commented 1 year ago

I think this should be the default behaviour.

Yes, I agree.

What do you think? We could use let* and instead optionally filter the list before sorting it against the index, so that previous behaviour could be preserved by enabling a feature-flag?

Sounds good to me.

johnhamelink commented 1 year ago

Ok, I might have time to contribute a PR this evening :)

uqix commented 6 months ago

justl-include-private-recipes does not work, is it supposed to handle this?