Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Support wildcard target #1646

Open
p-fruck opened this issue Jul 17, 2023 · 3 comments
Open

[Feature] Support wildcard target #1646

p-fruck opened this issue Jul 17, 2023 · 3 comments

Comments

@p-fruck
Copy link

p-fruck commented Jul 17, 2023

I recently came across this useful tool and since have been replacing Makefiles in many of my projects with Justfiles. However, there is one make feature that I cannot achieve using make:

In projects that use a containerized dev setup, my last Makefile entry used to be

# pass all commands to compose cli
%:
    docker-compose $@

This allowed to execute convenience functions like make up, make down, make build, make ps etc very quickly. When using just, I have to use the following code to achieve the same thing:

# docker-compose
@compose *flags:
    {{ compose }} {{ flags }}

# docker-compose up
@up *flags: _data
    {{ compose }} up {{ flags }}

# docker-compose down
@down *flags:
    {{ compose }} down {{ flags }}

# docker-compose build
@build *flags:
    {{ compose }} build {{ flags }}

# docker-compose ps
@ps *flags:
    {{ compose }} ps {{ flags }}

# docker-compose pull
@pull *flags:
    {{ compose }} pull {{ flags }}

This way I can still use commands like just up -d, just ps but for commands not specified explicitly I will have to execute e.g. just compose config.

Would it be possible to create a default wildcard option in just to achieve something similar to what is possible using make?

@casey
Copy link
Owner

casey commented Jul 17, 2023

This could be done with an attribute making a recipe a fallback recipe, in case no other recipe matches, which would receive the full command line, including the recipe name, as arguments:

[fallback]
foo *args:
  {{ args }}

It probably shouldn't be called [fallback] though, since there's already the fallback setting.

@p-fruck
Copy link
Author

p-fruck commented Jul 17, 2023

I also thought about something like [default], which will likely also be misleading, the most descriptive attribute name I came across would be something like [catchall] (or [catch_all]). I also thought about something like [wildcard] but I don't think this name is really descriptive.

@fastfedora
Copy link

I'd love to see this too. My use case for just is that I work on different projects which each have standardized around a different package manager (and sometimes change package managers mid-project).

So I've created just files that allow me to type just start or just install and not worry about which package manager exists for a project. However, that means for the standard scripts in package.json, I have to go and re-define every script in my .justfile. Having a fallback script would allow me to do:

[fallback]
run script:
   pnpm run {{script}}

Then I could just type just test or just build and it would automatically use the correct package manager for the project I'm working in.

Also, rather than use a script attribute, the target name could be an asterisk to indicate it was the catch-all definition:

* script:
   pnpm run {{script}}

Since * is currently not allowed as a character for a target name, this wouldn't break any backwards compatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants