github.com/scaleway/scaleway-cli@v1.11.1/pkg/cli/cmd_port.go (about) 1 // Copyright (C) 2015 Scaleway. All rights reserved. 2 // Use of this source code is governed by a MIT-style 3 // license that can be found in the LICENSE.md file. 4 5 package cli 6 7 import "github.com/scaleway/scaleway-cli/pkg/commands" 8 9 var cmdPort = &Command{ 10 Exec: runPort, 11 UsageLine: "port [OPTIONS] SERVER [PRIVATE_PORT[/PROTO]]", 12 Description: "Lookup the public-facing port that is NAT-ed to PRIVATE_PORT", 13 Help: "List port mappings for the SERVER, or lookup the public-facing port that is NAT-ed to the PRIVATE_PORT", 14 } 15 16 func init() { 17 cmdPort.Flag.BoolVar(&portHelp, []string{"h", "-help"}, false, "Print usage") 18 cmdPort.Flag.StringVar(&portGateway, []string{"g", "-gateway"}, "", "Use a SSH gateway") 19 cmdPort.Flag.StringVar(&portSSHUser, []string{"-user"}, "root", "Specify SSH user") 20 cmdPort.Flag.IntVar(&portSSHPort, []string{"-p", "-port"}, 22, "Specify SSH port") 21 } 22 23 // FLags 24 var portHelp bool // -h, --help flag 25 var portGateway string // -g, --gateway flag 26 var portSSHUser string // --user flag 27 var portSSHPort int // -p, --port flag 28 29 func runPort(cmd *Command, rawArgs []string) error { 30 if portHelp { 31 return cmd.PrintUsage() 32 } 33 if len(rawArgs) < 1 { 34 return cmd.PrintShortUsage() 35 } 36 37 args := commands.PortArgs{ 38 Gateway: portGateway, 39 Server: rawArgs[0], 40 SSHUser: portSSHUser, 41 SSHPort: portSSHPort, 42 } 43 ctx := cmd.GetContext(rawArgs) 44 return commands.RunPort(ctx, args) 45 }