justl.el icon indicating copy to clipboard operation
justl.el copied to clipboard

Handing private commands

Open johnhamelink opened this issue 2 years ago • 3 comments

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!

johnhamelink avatar Sep 12 '23 09:09 johnhamelink

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.

psibi avatar Sep 13 '23 02:09 psibi

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

johnhamelink avatar Sep 13 '23 07:09 johnhamelink

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

uqix avatar Feb 21 '24 01:02 uqix

The latest change handles this, thanks for the report!

psibi avatar Nov 15 '24 05:11 psibi