forked from rancher/cli
/
up.go
64 lines (56 loc) · 1.53 KB
/
up.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
package cmd
import (
"github.com/docker/libcompose/project"
rancherApp "github.com/rancher/rancher-compose/app"
"github.com/urfave/cli"
)
func UpCommand() cli.Command {
factory := &projectFactory{}
cmd := rancherApp.UpCommand(factory)
cmd.Flags = append(cmd.Flags, []cli.Flag{
cli.StringFlag{
Name: "rancher-file",
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",
},
cli.StringSliceFlag{
Name: "file,f",
Usage: "Specify one or more alternate compose files (default: docker-compose.yml)",
Value: &cli.StringSlice{},
EnvVar: "COMPOSE_FILE",
},
cli.StringFlag{
Name: "stack,s",
Usage: "Specify an alternate project name (default: directory name)",
},
}...)
return cmd
}
type projectFactory struct {
}
func (p *projectFactory) Create(c *cli.Context) (project.APIProject, error) {
config, err := lookupConfig(c)
if err != nil {
return nil, err
}
url, err := config.EnvironmentURL()
if err != nil {
return nil, err
}
// from config
c.GlobalSet("url", url)
c.GlobalSet("access-key", config.AccessKey)
c.GlobalSet("secret-key", config.SecretKey)
// copy from flags
c.GlobalSet("rancher-file", c.String("rancher-file"))
c.GlobalSet("env-file", c.String("env-file"))
c.GlobalSet("project-name", c.String("stack"))
for _, f := range c.StringSlice("file") {
c.GlobalSet("file", f)
}
factory := &rancherApp.ProjectFactory{}
return factory.Create(c)
}