forked from rancher/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathup.go
48 lines (42 loc) · 915 Bytes
/
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
package cmd
import (
"os"
"github.com/rancher/cli/cliclient"
client "github.com/rancher/rancher/pkg/client/generated/management/v3"
"github.com/urfave/cli"
)
func UpCommand() cli.Command {
return cli.Command{
Name: "up",
Usage: "apply compose config",
Action: defaultAction(apply),
Flags: []cli.Flag{
cli.StringFlag{
Name: "file,f",
Usage: "The location of compose config file",
},
},
}
}
func apply(ctx *cli.Context) error {
cf, err := lookupConfig(ctx)
if err != nil {
return err
}
c, err := cliclient.NewManagementClient(cf)
if err != nil {
return err
}
filePath := ctx.String("file")
compose, err := os.ReadFile(filePath)
if err != nil {
return err
}
globalComposeConfig := &client.ComposeConfig{
RancherCompose: string(compose),
}
if _, err := c.ManagementClient.ComposeConfig.Create(globalComposeConfig); err != nil {
return err
}
return nil
}