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

How to forward args? (Like "$@" in bash) #631

Closed
Boscop opened this issue May 31, 2020 · 5 comments
Closed

How to forward args? (Like "$@" in bash) #631

Boscop opened this issue May 31, 2020 · 5 comments
Labels

Comments

@Boscop
Copy link

Boscop commented May 31, 2020

How can I forward args to a subcommand (e.g. cargo)?
(Like "$@" in bash)

@Boscop Boscop changed the title How to forward args? How to forward args? (Like "$@" in bash) May 31, 2020
@casey
Copy link
Owner

casey commented Jun 1, 2020

Do you want to forward a fixed number of arguments, or a variable number of arguments?

All arguments can be forwarded, even if variadic:

bar +b:
	echo {{b}}

foo +a: (bar a)

But there isn't a direct equivalent of $@.

@casey casey added the question label Jun 1, 2020
@Boscop
Copy link
Author

Boscop commented Jun 8, 2020

@casey Thanks. +a works with forwarding, but then it requires at least one arg. How can I also accept zero args?

@casey
Copy link
Owner

casey commented Jun 8, 2020

If you give it the empty string as a default argument, it will accept zero args:

bar +b="":
	echo {{b}}

This is definitely somewhat cumbersome. I'm not sure why I didn't just give it this behavior to begin with, but at this point I think it would be reasonable to add * that accepts zero or more arguments, and evaluates to the empty string when no arguments are given.

@Boscop
Copy link
Author

Boscop commented Jun 8, 2020

@casey I actually tried *a hoping that it would allow "zero or more" args. I think that would be the most intuitive.
(Well, even more intuitive would be to not distinguish between * and + at all.)

@casey
Copy link
Owner

casey commented Jun 8, 2020

Agreed! I just opened #633, to add * with that behavior. Although I'm not sure when it'll get done, since other projects are taking all my cycles.

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

No branches or pull requests

2 participants