just
just copied to clipboard
Support for `match` expressions
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.
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.
I think this would be pretty reasonable. Syntax TBH, but I don't see why not.
I personally like the idea of staying as close to the Rust syntax for match as possible -- I think it's pretty concise and easy to read, for starters.