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

Support for match expressions #1990

Open
t3hmrman opened this issue Apr 5, 2024 · 3 comments
Open

Support for match expressions #1990

t3hmrman opened this issue Apr 5, 2024 · 3 comments

Comments

@t3hmrman
Copy link
Contributor

t3hmrman commented Apr 5, 2024

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
Copy link

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.

@casey
Copy link
Owner

casey commented May 15, 2024

I think this would be pretty reasonable. Syntax TBH, but I don't see why not.

@t3hmrman
Copy link
Contributor Author

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.

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