-
Notifications
You must be signed in to change notification settings - Fork 13
/
main.go
65 lines (52 loc) · 2.19 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
package main
import (
"fmt"
"os"
kingpin "gopkg.in/alecthomas/kingpin.v2"
)
const applicationName = "dcsg"
const applicationVersion = "v0.4.0"
var (
app = kingpin.New(applicationName, fmt.Sprintf("%s creates systemd services for Docker Compose projects (%s)", applicationName, applicationVersion))
appDryRun = app.Flag("dry-run", "Print details of what would be done but do not install anything").Short('n').Bool()
// install
installCommand = app.Command("install", "Register a systemd service for the given docker-compose file")
installDockerComposeFile = installCommand.Arg("docker-compose-file", "A docker-compose file").Default("docker-compose.yml").String()
installProjectName = installCommand.Arg("project-name", "The project name of the docker-compose project").String()
installDontPull = installCommand.Flag("no-pull", "The project name of the docker-compose project").Bool()
// uninstall
uninstallCommand = app.Command("uninstall", "Uninstall the systemd service for the given docker-compose file")
uninstallDockerComposeFile = uninstallCommand.Arg("docker-compose-file", "A docker-compose file").Default("docker-compose.yml").String()
uinstallProjectName = uninstallCommand.Arg("project-name", "The project name of the docker-compose project").String()
)
func init() {
app.Version(applicationVersion)
app.Author("Andreas Koch <[email protected]>")
}
func main() {
handleCommandlineArgument(os.Args[1:])
}
func handleCommandlineArgument(arguments []string) {
switch kingpin.MustParse(app.Parse(arguments)) {
case installCommand.FullCommand():
service, err := newDscg(*installDockerComposeFile, *installProjectName, *appDryRun, !(*installDontPull))
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
os.Exit(1)
}
if err := service.Install(); err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
os.Exit(1)
}
case uninstallCommand.FullCommand():
service, err := newDscg(*uninstallDockerComposeFile, *uinstallProjectName, *appDryRun, !(*installDontPull))
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
os.Exit(1)
}
if err := service.Uninstall(); err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
os.Exit(1)
}
}
}