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

Add CLI support for command templates/matrix commands #517

Open
cdrini opened this issue Nov 21, 2024 · 3 comments · May be fixed by #526
Open

Add CLI support for command templates/matrix commands #517

cdrini opened this issue Nov 21, 2024 · 3 comments · May be fixed by #526

Comments

@cdrini
Copy link
Contributor

cdrini commented Nov 21, 2024

It would be useful to be able to generate the commands dynamically based on an environment variable. For example:

concurrently --matrix "A B C" "echo {}"

Which would be equivalent to typing:

concurrently "echo A" "echo B" "echo C"

Or with multiple values you could do:

concurrently --matrix "A B C" --matrix "1 2 3" "echo {1}{2}"

Which would be equivalent to writing:

concurrently "echo A1" "echo "A2" "echo A3" "echo B1" "echo B2" "echo B3" "echo C1" "echo C2" "echo C3"

This would be useful for common repetitive tasks that can happen in parallel. For example, let's say I want to download some docker image on a few different servers. I could do:

SERVERS="server1 server2"
IMAGES="python:3.11 node:20"

concurrently --group --matrix "$SERVERS" --matrix "$IMAGES" "ssh {1} 'docker pull {2}'"

This would help making concurrently a drop-in replacement for bash for-loops; the above would replace

for server in $SERVERS; do
    for image in $IMAGES; do
        ssh $server "docker pull $image"
    done
done

It would also make concurrently a drop-in for a lot of gnu parallel usages, eg:

parallel --quote ssh {1} "docker pull {2}" ::: $SERVERS ::: $IMAGES

Another example: processing a lot files in parallel, eg less compiling a number of files:

concurrently --matrix "$(ls *.less)" --group "lessc {}"
@gustavohenke
Copy link
Member

Hey, thanks for the suggestion.

We already have the syntax parsing built into concurrently, it's the passthrough args (docs - https://github.com/open-cli-tools/concurrently/blob/8d3f9761bf6269ae9abdd5dbb661314b9980d62d/docs/cli/passthrough-arguments.md), though where it lacks is combining all the input combinations, which is what you're asking for.

As for which flag should activate it, I'm on the fence between reusing --passthrough-arguments/-P with a matrix value, or adding a separate --matrix, even if as a shortcut. Thoughts?

Tagged it as pull requests welcome, if anyone is keen on implementing this!

@cdrini
Copy link
Contributor Author

cdrini commented Jan 15, 2025

I think --passthrough-arguments might work differently ; that will always still only run the number of commands specified, but change their arguments. --matrix will always change (multiply) the commands specified.

--passthrough-arguments is kind of like an append to each of the existing commands, whereas --matrix is like multiplying the commands.

I think :P If I'm understanding that feature correctly.

@cdrini cdrini linked a pull request Jan 16, 2025 that will close this issue
@cdrini
Copy link
Contributor Author

cdrini commented Jan 16, 2025

Ok having implemented it now I think I see what you mean :P There is something between the two features, but I'm not quite finding the way to DRY them up. I think they might be different enough to warrant different names -- and passthrough only allows one list as input, whereas matrix can take multiple lists, which I'm having trouble finding a way to reconcile.

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

Successfully merging a pull request may close this issue.

2 participants