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

call function for invoking recipes in expressions #2538

Open
casey opened this issue Dec 21, 2024 · 2 comments
Open

call function for invoking recipes in expressions #2538

casey opened this issue Dec 21, 2024 · 2 comments
Labels

Comments

@casey
Copy link
Owner

casey commented Dec 21, 2024

I haven't really thought very hard about this, but it seems like it should be possible to create a call function which takes as its first argument a recipe name, and then invokes that recipe with some arguments, and returns whatever that recipe writes to standard out:

# baz evaluates to "Hello, bar!"
baz := call(foo, "bar");

foo message:
  echo "Hello, {{ message }}!"

This could also be used to evoke recipes in the middle of other recipes:

bar:
  # {{ call(foo) }}

Without needing to recursively invoke just.

@casey
Copy link
Owner Author

casey commented Dec 21, 2024

I'm sure there are tons of weird considerations and edge cases, like what if a recipe depends on a variable whose value depends on an invocation of call. In that particular case though, this is the same kind of loop detection that we already do for variables and recipe dependencies, and if all calls to call are statically resolvable (which they should be), then we could detect this easily.

@casey casey added the coveted label Dec 21, 2024
@casey
Copy link
Owner Author

casey commented Dec 22, 2024

Also, this function could not be parsed like normal functions, since its argument is not a value, but a recipe, so maybe it needs its own syntax:

(foo)("bar")
foo.call("bar")
…

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

1 participant