casey / just

🤖 Just a command runner
https://just.systems
Creative Commons Zero v1.0 Universal
20.09k stars 449 forks source link

[Feature] Support globbing with includes directive #1641

Open th3fallen opened 1 year ago

th3fallen commented 1 year ago

It would be amazing to be able to do !include path/to/my/subjusts/*.just and move on with life vs including each seperately.

IrrationalPi commented 1 year ago

I would love this feature also. I used it a lot with make to divide makefiles into like functionality.

Here is a workaround. The update recipe will scan a folder for all *.just files, format them, create a temporary Justfile with all the !include directives, then dump them to a single Justfile. I have found !include to be too buggy for daily use in the primary Justfile.

Initial Justfile: !include ./justfiles/self.just

./justfiles/self.just:

justfile_dir := "./justfiles"

update:
    #!/usr/bin/env bash
    set -euxo pipefail
    cp Justfile Justfile.bak
    echo "# DO NOT EDIT. Auto-generated. Update with 'just update'." > Justfile.includes
    for file in {{ justfile_dir }}/*.just; do
        echo "!include ${file}" >> Justfile.includes
        just --justfile "${file}" --fmt --unstable || true
    done
    just --unstable --justfile Justfile.includes --dump > Justfile
    rm Justfile.includes

After making any changes to a *.just file in your watched folder, run: just update

casey commented 8 months ago

This seems reasonable. include has been stabilized as import, so this wouldn't technically be backwards compatible, but I think that * in paths is so vanishingly rare that we can go ahead and do it.