/
cmd_port.go
45 lines (38 loc) · 1.39 KB
/
cmd_port.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
// 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 cmdPort = &Command{
Exec: runPort,
UsageLine: "port [OPTIONS] SERVER [PRIVATE_PORT[/PROTO]]",
Description: "Lookup the public-facing port that is NAT-ed to PRIVATE_PORT",
Help: "List port mappings for the SERVER, or lookup the public-facing port that is NAT-ed to the PRIVATE_PORT",
}
func init() {
cmdPort.Flag.BoolVar(&portHelp, []string{"h", "-help"}, false, "Print usage")
cmdPort.Flag.StringVar(&portGateway, []string{"g", "-gateway"}, "", "Use a SSH gateway")
cmdPort.Flag.StringVar(&portSSHUser, []string{"-user"}, "root", "Specify SSH user")
cmdPort.Flag.IntVar(&portSSHPort, []string{"-p", "-port"}, 22, "Specify SSH port")
}
// FLags
var portHelp bool // -h, --help flag
var portGateway string // -g, --gateway flag
var portSSHUser string // --user flag
var portSSHPort int // -p, --port flag
func runPort(cmd *Command, rawArgs []string) error {
if portHelp {
return cmd.PrintUsage()
}
if len(rawArgs) < 1 {
return cmd.PrintShortUsage()
}
args := commands.PortArgs{
Gateway: portGateway,
Server: rawArgs[0],
SSHUser: portSSHUser,
SSHPort: portSSHPort,
}
ctx := cmd.GetContext(rawArgs)
return commands.RunPort(ctx, args)
}