casey / just

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

Support for custom named arguments? (e.g. --foo 42 --bar -f) #2001

Open alshdavid opened 1 month ago

alshdavid commented 1 month ago

Hi, I'm loving using just as a basic task runner! It's made working with my projects much easier.

I'm wondering if the project would consider adding custom named arguments that could be passed into recipes as variables?

I'd love to use:

just build --foo 42 --bar -f

Currently we can use recipe parameters however they must be supplied in order making it difficult to combine optional parameters with variadic arguments

Take for instance this use case:

profile := env_var_or_default("profile", "")

run *ARGS:
  cargo run {{ if profile != "" { " --profile " + profile } else { "" }  }} {{ARGS}}
profile=release-lto just run foo bar
> cargo run --profile release-lto foo bar

profile is an optional value passed in as an environment variable however it isn't listed when running just --list

It would be great if just supported optional custom named arguments, as long as they didn't conflict with existing keys so the above could be consumed as

just run --profile release-lto foo bar
> cargo run --profile release-lto foo bar

just --list
> Available recipes:
>   run --profile="" *ARGS=""

Thanks 🙏