Skip to content

Commit 27bc1ca

Browse files
committed
Add flag to allow tasks provided on the command line to be run in parallel
1 parent 3084ef1 commit 27bc1ca

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

cmd/task/task.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func main() {
5858
silent bool
5959
dry bool
6060
summary bool
61+
parallel bool
6162
dir string
6263
entrypoint string
6364
output string
@@ -71,6 +72,7 @@ func main() {
7172
pflag.BoolVarP(&watch, "watch", "w", false, "enables watch of the given task")
7273
pflag.BoolVarP(&verbose, "verbose", "v", false, "enables verbose mode")
7374
pflag.BoolVarP(&silent, "silent", "s", false, "disables echoing")
75+
pflag.BoolVarP(&parallel, "parallel", "p", false, "executes tasks provided on command line in parallel")
7476
pflag.BoolVar(&dry, "dry", false, "compiles and prints tasks in the order that they would be run, without executing them")
7577
pflag.BoolVar(&summary, "summary", false, "show summary about a task")
7678
pflag.StringVarP(&dir, "dir", "d", "", "sets directory of execution")
@@ -114,6 +116,7 @@ func main() {
114116
Dry: dry,
115117
Entrypoint: entrypoint,
116118
Summary: summary,
119+
Parallel: parallel,
117120

118121
Stdin: os.Stdin,
119122
Stdout: os.Stdout,

task.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type Executor struct {
4141
Silent bool
4242
Dry bool
4343
Summary bool
44+
Parallel bool
4445

4546
Stdin io.Reader
4647
Stdout io.Writer
@@ -77,12 +78,18 @@ func (e *Executor) Run(ctx context.Context, calls ...taskfile.Call) error {
7778
return e.watchTasks(calls...)
7879
}
7980

81+
g, ctx := errgroup.WithContext(ctx)
8082
for _, c := range calls {
81-
if err := e.RunTask(ctx, c); err != nil {
82-
return err
83+
c := c
84+
if e.Parallel {
85+
g.Go(func() error { return e.RunTask(ctx, c) })
86+
} else {
87+
if err := e.RunTask(ctx, c); err != nil {
88+
return err
89+
}
8390
}
8491
}
85-
return nil
92+
return g.Wait()
8693
}
8794

8895
// Setup setups Executor's internal state

0 commit comments

Comments
 (0)