forked from rancher/cli
/
start.go
37 lines (32 loc) · 1.08 KB
/
start.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
package cmd
import (
"strings"
"github.com/rancher/go-rancher/v2"
"github.com/urfave/cli"
)
var (
startTypes = []string{"service", "container", "host", "stack"}
)
func StartCommand() cli.Command {
return cli.Command{
Name: "start",
ShortName: "activate",
Usage: "Start or activate " + strings.Join(startTypes, ", "),
Description: "\nStart resources by ID or name in the current $RANCHER_ENVIRONMENT. Use `--env <envID>` or `--env <envName>` to select a different environment.\n\nExample:\n\t$ rancher start 1s70\n\t$ rancher --env 1a5 start stackName/serviceName \n",
ArgsUsage: "[ID NAME...]",
Action: startResources,
Flags: []cli.Flag{
typesStringFlag(startTypes),
},
}
}
func startResources(ctx *cli.Context) error {
return forEachResource(ctx, startTypes, func(c *client.RancherClient, resource *client.Resource) (string, error) {
action, err := pickAction(resource, "start", "activate", "activateservices")
if err != nil {
return "", err
}
err = c.Action(resource.Type, action, resource, nil, resource)
return resource.Id, err
})
}