1
0
mirror of https://github.com/go-task/task.git synced 2025-08-10 22:42:19 +02:00

Merge pull request #266 from RossHammer/master

Add flag to allow tasks provided on the command line to be run in parallel
This commit is contained in:
Andrey Nering
2019-11-15 23:22:53 -03:00
committed by GitHub
2 changed files with 13 additions and 3 deletions

View File

@@ -58,6 +58,7 @@ func main() {
silent bool silent bool
dry bool dry bool
summary bool summary bool
parallel bool
dir string dir string
entrypoint string entrypoint string
output string output string
@@ -71,6 +72,7 @@ func main() {
pflag.BoolVarP(&watch, "watch", "w", false, "enables watch of the given task") pflag.BoolVarP(&watch, "watch", "w", false, "enables watch of the given task")
pflag.BoolVarP(&verbose, "verbose", "v", false, "enables verbose mode") pflag.BoolVarP(&verbose, "verbose", "v", false, "enables verbose mode")
pflag.BoolVarP(&silent, "silent", "s", false, "disables echoing") pflag.BoolVarP(&silent, "silent", "s", false, "disables echoing")
pflag.BoolVarP(&parallel, "parallel", "p", false, "executes tasks provided on command line in parallel")
pflag.BoolVar(&dry, "dry", false, "compiles and prints tasks in the order that they would be run, without executing them") pflag.BoolVar(&dry, "dry", false, "compiles and prints tasks in the order that they would be run, without executing them")
pflag.BoolVar(&summary, "summary", false, "show summary about a task") pflag.BoolVar(&summary, "summary", false, "show summary about a task")
pflag.StringVarP(&dir, "dir", "d", "", "sets directory of execution") pflag.StringVarP(&dir, "dir", "d", "", "sets directory of execution")
@@ -114,6 +116,7 @@ func main() {
Dry: dry, Dry: dry,
Entrypoint: entrypoint, Entrypoint: entrypoint,
Summary: summary, Summary: summary,
Parallel: parallel,
Stdin: os.Stdin, Stdin: os.Stdin,
Stdout: os.Stdout, Stdout: os.Stdout,

13
task.go
View File

@@ -41,6 +41,7 @@ type Executor struct {
Silent bool Silent bool
Dry bool Dry bool
Summary bool Summary bool
Parallel bool
Stdin io.Reader Stdin io.Reader
Stdout io.Writer Stdout io.Writer
@@ -77,12 +78,18 @@ func (e *Executor) Run(ctx context.Context, calls ...taskfile.Call) error {
return e.watchTasks(calls...) return e.watchTasks(calls...)
} }
g, ctx := errgroup.WithContext(ctx)
for _, c := range calls { for _, c := range calls {
if err := e.RunTask(ctx, c); err != nil { c := c
return err if e.Parallel {
g.Go(func() error { return e.RunTask(ctx, c) })
} else {
if err := e.RunTask(ctx, c); err != nil {
return err
}
} }
} }
return nil return g.Wait()
} }
// Setup setups Executor's internal state // Setup setups Executor's internal state