forked from scaleway/scaleway-cli
/
cmd_attach.go
44 lines (37 loc) · 1.17 KB
/
cmd_attach.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
// 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 cmdAttach = &Command{
Exec: runAttach,
UsageLine: "attach [OPTIONS] SERVER",
Description: "Attach to a server serial console",
Help: "Attach to a running server serial console.",
Examples: `
$ scw attach my-running-server
$ scw attach $(scw start my-stopped-server)
$ scw attach $(scw start $(scw create ubuntu-vivid))
`,
}
func init() {
cmdAttach.Flag.BoolVar(&attachHelp, []string{"h", "-help"}, false, "Print usage")
cmdAttach.Flag.BoolVar(&attachNoStdin, []string{"-no-stdin"}, false, "Do not attach stdin")
}
// Flags
var attachHelp bool // -h, --help flag
var attachNoStdin bool // --no-stdin flag
func runAttach(cmd *Command, rawArgs []string) error {
if attachHelp {
return cmd.PrintUsage()
}
if len(rawArgs) != 1 {
return cmd.PrintShortUsage()
}
args := commands.AttachArgs{
NoStdin: attachNoStdin,
Server: rawArgs[0],
}
ctx := cmd.GetContext(rawArgs)
return commands.RunAttach(ctx, args)
}