This repository has been archived by the owner on Sep 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
87 lines (73 loc) · 1.71 KB
/
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
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
85
86
87
package main
import (
"flag"
"fmt"
"log"
"os"
"github.com/morfien101/chef-waiter/logs"
"github.com/morfien101/service"
)
// VERSION holds the version of the program
// Don't change this as the build server tags the builds.
var VERSION = "1.0.0"
// Flags for the application launch
var (
versionCheck = flag.Bool("v", false, "Outputs the version of the program.")
helpFlag = flag.Bool("h", false, "Shows the help menu")
svcFlag = flag.String("service", "", "Control the system service.")
logger logs.SysLogger
)
func main() {
// Deal with flags
digestFlags()
svcConfig := &service.Config{
Name: "chefwaiter",
DisplayName: "Chef Waiter",
Description: "Chef Waiter: API that allows you to control the chef client remotely.",
}
prg := &program{}
serviceController, err := service.New(prg, svcConfig)
if err != nil {
log.Fatal(err)
}
// Create a channel to house the errors from the service.
// These are then printed out on the go func below.
errsChan := make(chan error, 5)
logger, err = serviceController.Logger(errsChan)
if err != nil {
log.Fatal(err)
}
go func() {
for {
err := <-errsChan
if err != nil {
log.Print(err)
}
}
}()
// Look for the --service flag and do what we need to here.
if len(*svcFlag) != 0 {
err := service.Control(serviceController, *svcFlag)
if err != nil {
log.Printf("Valid actions: %q\n", service.ControlAction)
log.Fatal(err)
}
return
}
err = serviceController.Run()
if err != nil {
logger.Error(err)
}
}
func digestFlags() {
// Parse the flags to get the state we need to run in.
flag.Parse()
if *versionCheck {
fmt.Println(VERSION)
os.Exit(0)
}
if *helpFlag {
flag.PrintDefaults()
os.Exit(0)
}
}