-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
94 lines (85 loc) · 2.06 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
88
89
90
91
92
93
94
package main
import (
"os"
"github.com/marcinhlybin/docker-env/cmd"
"github.com/marcinhlybin/docker-env/helpers"
"github.com/marcinhlybin/docker-env/logger"
"github.com/marcinhlybin/docker-env/version"
"github.com/urfave/cli/v2"
)
func main() {
app := &cli.App{
Name: "docker-env",
Usage: "Docker environments manager",
Version: version.Version,
Description: `All commands must run in the git repository directory of the project.
If environment name is not specified current branch name is used.`,
Commands: []*cli.Command{
&cmd.StartCommand,
&cmd.StopCommand,
&cmd.RestartCommand,
&cmd.RemoveCommand,
&cmd.ListCommand,
&cmd.ResetCommand,
&cmd.BuildCommand,
&cmd.InfoCommand,
&cmd.TerminalCommand,
&cmd.CodeCommand,
&cmd.VersionCommand,
&cmd.LogsCommand,
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config",
Aliases: []string{"c"},
Usage: "config file path",
},
&cli.BoolFlag{
Name: "debug",
Aliases: []string{"d"},
Usage: "enable debug mode",
},
&cli.BoolFlag{
Name: "quiet",
Aliases: []string{"q"},
Usage: "disable info messages",
},
&cli.BoolFlag{
Name: "quieter",
Aliases: []string{"qq"},
Usage: "disable docker output",
},
},
Before: func(c *cli.Context) error {
// Show help if no arguments
if c.NArg() == 0 {
cli.ShowAppHelpAndExit(c, 0)
}
// Enable debug mode
showDebug := c.Bool("debug")
logger.SetDebug(showDebug)
// Disable info messages
// Docker output is still visible
quiet := c.Bool("quiet")
logger.SetQuiet(quiet)
// Disable all output except errors
quieter := c.Bool("quieter")
logger.SetQuieter(quieter)
return nil
},
}
// Version
cli.VersionFlag = &cli.BoolFlag{
Name: "version",
Aliases: []string{"v"},
Usage: "show version string, alias for 'version --short'",
}
cli.VersionPrinter = func(c *cli.Context) {
version.PrintVersionString()
}
err := app.Run(os.Args)
if err != nil {
logger.Error("%s", helpers.ToTitle(err.Error()))
os.Exit(1)
}
}