1
0
mirror of https://github.com/rancher/cli.git synced 2026-02-05 09:48:36 +01:00
Files
cli/cmd/stop.go
Daishan Peng 03ebe1a203 cli 2.0
2017-09-15 14:34:17 -07:00

37 lines
1.1 KiB
Go

package cmd
import (
"strings"
"github.com/rancher/go-rancher/v3"
"github.com/urfave/cli"
)
var (
stopTypes = []string{"service", "container", "host", "stack"}
)
func StopCommand() cli.Command {
return cli.Command{
Name: "stop",
ShortName: "deactivate",
Usage: "Stop or deactivate " + strings.Join(stopTypes, ", "),
Description: "\nStop 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 stop 1s70\n\t$ rancher --env 1a5 stop stackName/serviceName \n",
ArgsUsage: "[ID NAME...]",
Action: stopResources,
Flags: []cli.Flag{
typesStringFlag(stopTypes),
},
}
}
func stopResources(ctx *cli.Context) error {
return forEachResource(ctx, stopTypes, func(c *client.RancherClient, resource *client.Resource) (string, error) {
action, err := pickAction(resource, "stop", "deactivate", "deactivateservices")
if err != nil {
return "", err
}
return resource.Id, c.Action(resource.Type, action, resource, nil, resource)
})
}