casey / just

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

Support for `match` expressions #1990

Open t3hmrman opened 1 month ago

t3hmrman commented 1 month ago

Hey thanks for the awesome tool.

One thing I'd love to have from the Rust world in my Justfiles is the match expression. In particular I want to use it to achieve some cross-platform (so matching on os() for example).

Does this seem feasible, and is it something we might want in just long term? I'm happy to do the work to implement if so.

sambonbonne commented 1 week ago

I have a similar use case: I use a justfile to run some commands with a specific environment.

One of the commands have subcommands and when running a specific subcommand, I want to pass extra args that are not required for other subcommands.

Here is what I do in my file:

EXTRA_ARG := "example"

my-command command *args='':
    the-command {{ if command == "specific" {  "specific --extra-arg " + EXTRA_ARG } else { command + " " + args } }}

As you can see, this is not really intuitive to read and something like this could be easier to understand:

EXTRA_ARG := "example"

my-command command *args='':
    {{ match command:
        "specific": "the-command specific --extra-arg " + EXTRA_ARG + " " + args
        any: "the-command " + any + " " + args
    }}

Please note that this is an example of something I would find more readable but I'm not a "language designer" and I'm sure a better syntax can be found.