-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.go
84 lines (68 loc) · 1.74 KB
/
cli.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"fmt"
"os"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
var (
flagDebug bool
)
var rootCmd = &cobra.Command{
Use: "runon [host] [args]...",
Short: "runon syncs workspaces of projects, optionally runs commands in them if changes needed syncing and then runs passed commands",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
persistentFlagCommonalities(cmd)
host := args[0]
runArgs := args[1:]
Run(cmd, host, runArgs)
},
}
var masterControlCommand = &cobra.Command{
Use: "master [host]",
Short: "Run MasterControl in daemon mode",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
persistentFlagCommonalities(cmd)
host := args[0]
RunMasterOnly(host)
},
}
var initCommand = &cobra.Command{
Use: "init",
Short: "Init bare .runon.yml file",
Run: func(cmd *cobra.Command, args []string) {
persistentFlagCommonalities(cmd)
InitConfig()
},
}
var cleanCommand = &cobra.Command{
Use: "clean [host]",
Short: "Clean remote dir",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
persistentFlagCommonalities(cmd)
host := args[0]
Clean(host)
},
}
func persistentFlagCommonalities(cmd *cobra.Command) {
if flagDebug {
log.SetLevel(log.DebugLevel)
log.Info("enabling debug-mode")
}
}
func init() {
rootCmd.AddCommand(masterControlCommand)
rootCmd.AddCommand(cleanCommand)
rootCmd.AddCommand(initCommand)
rootCmd.Flags().StringP("copy-back", "b", "", "paths to copy back from the host after the commands ran through")
rootCmd.PersistentFlags().BoolVar(&flagDebug, "debug", false, "Enable debug output")
}
func main() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}