-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathrun.go
More file actions
44 lines (39 loc) · 1.04 KB
/
run.go
File metadata and controls
44 lines (39 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package cmd
import (
"errors"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"golang.org/x/sync/errgroup"
)
// runCmd represents the version command
var runCmd = &cobra.Command{
Use: "run [scripts]",
Short: "Executes one or more scripts in parallel",
Long: `Executes one or more scripts in parallel
All scripts will run to completion, regardless of whether or not the other scripts exit with errors.
Should any of the scripts fail Leeway will exit with an exit code of 1 once all scripts are done executing.
`,
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
g := new(errgroup.Group)
for _, scriptName := range args {
scriptName := scriptName
g.Go(func() error {
_, _, script, _ := getTarget([]string{scriptName}, true)
if script == nil {
return errors.New("run needs a script")
}
opts, _ := getBuildOpts(cmd)
return script.Run(opts...)
})
}
err := g.Wait()
if err != nil {
log.Fatal(err)
}
},
}
func init() {
rootCmd.AddCommand(runCmd)
addBuildFlags(runCmd)
}