-
Notifications
You must be signed in to change notification settings - Fork 256
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
Enhancement: Simpler way to execute multiple commands #455
Comments
So, I am sympathetic to the view that writing multiple command line commands in mage is a little wordy. However, I don't think this is the right fix. One problem is that you can't know what has succeeded and what has failed. So you won't know what needs to be cleaned up afterward. Second is that the implementation uses errgroup.Group.Go, which runs the code in a goroutine, which is probably not what most people would expect. Most people would expect the code to be run sequentially. For example, in your code, I think most people would expect My suggestion would be to use a mechanism like mg.Deps uses, where instead of returning an error, it panics with a special value, and the rest of the mage infrastructure just knows how to deal with that panic value, and converts it into an error message for the user. so, for example:
I'll have to think some more about it. It's doable, but it needs some thought to make sure we cover all the bases. |
You can, this is an example of a failed build:
As you can see, it shows exactly what's going wrong.
Thanks to the
This sounds rather elaborate to me, and goes against my personal 'don't use panic for actual program logic' approach. However, I do like your example, as it's really clean & simple. Which was the whole point of this exercise.
Yeah, that's why I wanted to discuss before spending more time on the actual code itself ;-) Going slightly off-topic, this is some code I also added to my own func rm(path ...string) error {
for _, p := range path {
if err := sh.Rm(p); err != nil {
return err
}
}
return nil
} Maybe |
Describe the feature
This is a proposal to simplify the execution of multiple commands, where an error should stop this chain. Basically the behaviour of
make
when executing multiple commands for a single target.What problem does this feature address?
AFAIK this is the way to execute multiple commands in a "build" target:
This means that for every command to execute there are typically three lines of code necessary. My proposal is to introduce something like this:
I think it's a good idea to make running shell commands as direct as possible.
Additional context
This is the way I implemented it locally. It does add the dependency on
golang.org/x/sync/errgroup
, so the code cannot be used as-is. I think it's relatively simple to restructure the code to avoid this dependency. Before doing that, I'd rather discuss the overall idea first, though.The text was updated successfully, but these errors were encountered: