-
Notifications
You must be signed in to change notification settings - Fork 476
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
for-each with Just? #1570
Comments
I second this. How can I iterate over a list of values? In my case, I want to bind values to parameters interpolated within commands. |
do task arguments suit your needs? |
there is an example on readme using bash for loop, have you tried this one? |
The bash for loop doesn't seem applicable. Here's an example. Given a collection ["one", "two", "three"], how would we iterate over its elements, using each element within string interpolated commands executed by just? |
Example: recipe context +collection:
#!/bin/sh
if [ '{{collection}}' != '' ]; then
for item in {{collection}}; do
just dynamic-{{context}} $item
done
else
echo "No collection to process with dynamic-{{context}}"
fi or something like that? That's how I tend to do it. Unless the recipe may end up on a Windows system in which case I usually use PowerShell instead of a POSIX compliant shell for both platforms. |
I ended up doing this:
It's not fully implemented, as you can see, but it got me somewhat what I need. But it also is not very elegant... ^^' |
The plan is to eventually have Python built into Just so that it has a multi-platform (Windows and everything else) scripting language. But until then using an external language is usually best. I'm on Mac but often need to support Windows so I installed PowerShell Core on my Mac and utilize whatever version of PowerShell is installed on the Windows system to avoid installing anything on target systems beyond the Just executable. |
integrating a scripting-language sounds awesome, though I believe lua is the better choice for that, having worked on integrating both. Is there already an issue about that with some design decisions? Is it actually worth investing time, seeing other PRs don't get reviews? ( I fully understand lack of time on maintainer side, which is totally OK, I only want to prevent wasting time on something that won't get reviewed ) |
Hi, is there any updates? Iterating through a list is quite useful! |
Hey @casey, they claim it's not production ready but RustPython is in use by Ruff the Python linter. Maybe good enough now for most recipe scripting? |
I'd be a little cautious if it isn't production ready. We could land something as unstable, but if it was incompatible with python in unexpected ways, it might be frustrating. |
Personally I only care about the basics, as long it can accomplish the equivalent of Bourne shell with arrays or lists in a cross-platform way I'm all good. It would be wonderful if it was 100% Python 3.7+ compatible with no surprises but that's a minor benefit (to me) over just covering the shell basics. I've not investigated at all yet. Though I'm happy to investigate when a get some free time. That or just bake in Nushell which is also Rust based and there is embed-nu - Crates.io. Anything to get cross platform basic shell scripting would be a godsend. 👼 |
I think that exploring what Python support would look like is probably reasonable. It might not be ready to stabilize, but it would be interesting to see how it works. I'm worried that it'll drive compile times and binary size through the roof, but we can make it an optional feature. |
Another option is busybox. It's not pure rust, but it does come as a library, and I know busybox is very mature and widely used, so it could be a good option. |
See #2458, which floats the possibility of making all values lists of strings, which would easily allow a non-error-prone for loop. |
Hello!
I would like to automate the management of my docker-compose environments for self-hosted services to some degree, and a Justfile seems like a very clean solution. However, I couldn't find out how to dynamically create tasks.
Consider an array of
["jellyfin", "tubesync", "tvheadend"]
. I would like to be able to generate apropriate tasks for-down
,-pull
, and-start
.Is this possible?
Thanks!
The text was updated successfully, but these errors were encountered: