-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
49 lines (40 loc) · 829 Bytes
/
main.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
package main
import (
"castle/base"
"castle/exec"
"castle/parse"
"flag"
"fmt"
"os"
)
var (
configFile string
flagVersion bool
)
func init() {
base.Level = 10 // Hide all base logs
flag.StringVar(&configFile, "f", "castle.yaml", "Config file to use.")
flag.BoolVar(&flagVersion, "v", false, "Print version and exit.")
flag.Parse()
}
func main() {
// Version and exit
if flagVersion {
fmt.Println(base.VERSION)
os.Exit(0)
}
config := parse.Parse(configFile)
command := flag.Arg(0)
// No command
if command == "" {
fmt.Println("Please specify a command.")
os.Exit(1)
}
// e.g. castle init
if exec.IsSpecialCommand(command) {
exec.SpecialCommands[command](flag.Args()[1:])
os.Exit(0)
}
// Normal command
exec.ExecuteTask(config.TaskArgs[command], command, config.Config.LogShellCmds)
}