forked from rancher/rancher-compose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
88 lines (81 loc) · 1.93 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
package main
import (
"fmt"
"os"
"path"
"github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
"github.com/docker/libcompose/cli/command"
rancherApp "github.com/rancher/rancher-compose/app"
"github.com/rancher/rancher-compose/executor"
"github.com/rancher/rancher-compose/version"
)
func beforeApp(c *cli.Context) error {
if c.GlobalBool("verbose") {
logrus.SetLevel(logrus.DebugLevel)
}
return nil
}
func main() {
if path.Base(os.Args[0]) == "rancher-compose-executor" {
executor.Main()
} else {
cliMain()
}
}
func cliMain() {
factory := &rancherApp.ProjectFactory{}
app := cli.NewApp()
app.Name = "rancher-compose"
app.Usage = "Docker-compose to Rancher"
app.Version = version.VERSION
app.Author = "Rancher Labs, Inc."
app.Email = ""
app.Before = beforeApp
app.Flags = append(command.CommonFlags(),
cli.StringFlag{
Name: "url",
Usage: fmt.Sprintf(
"Specify the Rancher API endpoint URL",
),
EnvVar: "RANCHER_URL",
},
cli.StringFlag{
Name: "access-key",
Usage: fmt.Sprintf(
"Specify Rancher API access key",
),
EnvVar: "RANCHER_ACCESS_KEY",
},
cli.StringFlag{
Name: "secret-key",
Usage: fmt.Sprintf(
"Specify Rancher API secret key",
),
EnvVar: "RANCHER_SECRET_KEY",
},
cli.StringFlag{
Name: "rancher-file,r",
Usage: "Specify an alternate Rancher compose file (default: rancher-compose.yml)",
},
cli.StringFlag{
Name: "env-file,e",
Usage: "Specify a file from which to read environment variables",
},
)
app.Commands = []cli.Command{
rancherApp.CreateCommand(factory),
rancherApp.UpCommand(factory),
command.StartCommand(factory),
command.LogsCommand(factory),
rancherApp.RestartCommand(factory),
rancherApp.StopCommand(factory),
command.ScaleCommand(factory),
command.RmCommand(factory),
rancherApp.PullCommand(factory),
rancherApp.UpgradeCommand(factory),
}
if err := app.Run(os.Args); err != nil {
logrus.Fatal(err)
}
}