This repository has been archived by the owner on Sep 15, 2021. It is now read-only.
forked from scaleway/scaleway-cli
/
cmd_stop.go
50 lines (43 loc) · 1.41 KB
/
cmd_stop.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
// Copyright (C) 2015 Scaleway. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE.md file.
package cli
import "github.com/scaleway/scaleway-cli/pkg/commands"
var cmdStop = &Command{
Exec: runStop,
UsageLine: "stop [OPTIONS] SERVER [SERVER...]",
Description: "Stop a running server",
Help: "Stop a running server.",
Examples: `
$ scw stop my-running-server my-second-running-server
$ scw stop -t my-running-server my-second-running-server
$ scw stop $(scw ps -q)
$ scw stop $(scw ps | grep mysql | awk '{print $1}')
$ scw stop server && stop wait server
$ scw stop -w server
`,
}
func init() {
cmdStop.Flag.BoolVar(&stopT, []string{"t", "-terminate"}, false, "Stop and trash a server with its volumes")
cmdStop.Flag.BoolVar(&stopHelp, []string{"h", "-help"}, false, "Print usage")
cmdStop.Flag.BoolVar(&stopW, []string{"w", "-wait"}, false, "Synchronous stop. Wait for SSH to be ready")
}
// Flags
var stopT bool // -t flag
var stopHelp bool // -h, --help flag
var stopW bool // -w, --wait flat
func runStop(cmd *Command, rawArgs []string) error {
if stopHelp {
return cmd.PrintUsage()
}
if len(rawArgs) < 1 {
return cmd.PrintShortUsage()
}
args := commands.StopArgs{
Terminate: stopT,
Wait: stopW,
Servers: rawArgs,
}
ctx := cmd.GetContext(rawArgs)
return commands.RunStop(ctx, args)
}