-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.go
42 lines (38 loc) · 1.1 KB
/
run.go
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
package cmd
import (
"fmt"
"os"
"github.com/jevi061/ops/internal/ops"
"github.com/spf13/cobra"
)
var (
tag string
opsfile string
debug bool
dryRun bool
)
func NewRunCmd() *cobra.Command {
var runCmd = &cobra.Command{
Use: "run TASK...",
Args: cobra.MatchAll(cobra.MinimumNArgs(1)),
Short: "Run tasks",
Long: `Run tasks defined in Opsfile, eg: ops run task1 task2 ...`,
Run: func(cmd *cobra.Command, args []string) {
conf, err := ops.NewOpsfileFromPath(opsfile)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
o := ops.NewOps(conf, ops.WithDebug(debug), ops.WithDryRun(dryRun))
if err := o.Run(tag, args...); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
},
}
runCmd.PersistentFlags().StringVarP(&tag, "tag", "t", "", "server tag")
runCmd.PersistentFlags().StringVarP(&opsfile, "opsfile", "f", "./Opsfile.yml", "opsfile")
runCmd.PersistentFlags().BoolVarP(&debug, "debug", "d", false, "run tasks in debug mode")
runCmd.PersistentFlags().BoolVarP(&dryRun, "dry-run", "", false, "test task without applying changes")
return runCmd
}