Skip to content

Commit 99b210a

Browse files
committed
Can now pass gateway var using environment (#70, #71)
1 parent 0782d9f commit 99b210a

File tree

7 files changed

+29
-0
lines changed

7 files changed

+29
-0
lines changed

commands/cp.go

+6
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ func TarFromSource(apiClient *api.ScalewayAPI, source string) (*io.ReadCloser, e
8484
remoteCommand = append(remoteCommand, base)
8585

8686
// Resolve gateway
87+
if cpGateway == "" {
88+
cpGateway = os.Getenv("SCW_GATEWAY")
89+
}
8790
var gateway string
8891
if cpGateway == serverID || cpGateway == serverParts[0] {
8992
gateway = ""
@@ -178,6 +181,9 @@ func UntarToDest(apiClient *api.ScalewayAPI, sourceStream *io.ReadCloser, destin
178181
remoteCommand = append(remoteCommand, "-xf", "-")
179182

180183
// Resolve gateway
184+
if cpGateway == "" {
185+
cpGateway = os.Getenv("SCW_GATEWAY")
186+
}
181187
var gateway string
182188
if cpGateway == serverID || cpGateway == serverParts[0] {
183189
gateway = ""

commands/exec.go

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ func runExec(cmd *types.Command, args []string) {
5858
serverID := cmd.API.GetServerID(args[0])
5959

6060
// Resolve gateway
61+
if execGateway == "" {
62+
execGateway = os.Getenv("SCW_GATEWAY")
63+
}
6164
var gateway string
6265
var err error
6366
if execGateway == serverID || execGateway == args[0] {

commands/kill.go

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ func runKill(cmd *types.Command, args []string) {
4949
}
5050

5151
// Resolve gateway
52+
if killGateway == "" {
53+
killGateway = os.Getenv("SCW_GATEWAY")
54+
}
5255
var gateway string
5356
if killGateway == serverID || killGateway == args[0] {
5457
gateway = ""

commands/logs.go

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
package commands
66

77
import (
8+
"os"
9+
810
log "github.com/Sirupsen/logrus"
911

1012
"github.com/scaleway/scaleway-cli/api"
@@ -45,6 +47,9 @@ func runLogs(cmd *types.Command, args []string) {
4547
// FIXME: switch to serial history when API is ready
4648

4749
// Resolve gateway
50+
if logsGateway == "" {
51+
logsGateway = os.Getenv("SCW_GATEWAY")
52+
}
4853
var gateway string
4954
if logsGateway == serverID || logsGateway == args[0] {
5055
gateway = ""

commands/port.go

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
package commands
66

77
import (
8+
"os"
9+
810
log "github.com/Sirupsen/logrus"
911

1012
"github.com/scaleway/scaleway-cli/api"
@@ -43,6 +45,9 @@ func runPort(cmd *types.Command, args []string) {
4345
}
4446

4547
// Resolve gateway
48+
if portGateway == "" {
49+
portGateway = os.Getenv("SCW_GATEWAY")
50+
}
4651
var gateway string
4752
if portGateway == serverID || portGateway == args[0] {
4853
gateway = ""

commands/run.go

+3
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ func runRun(cmd *types.Command, args []string) {
101101
}
102102
} else {
103103
// Resolve gateway
104+
if runGateway == "" {
105+
runGateway = os.Getenv("SCW_GATEWAY")
106+
}
104107
gateway, err := api.ResolveGateway(cmd.API, runGateway)
105108
if err != nil {
106109
log.Fatalf("Cannot resolve Gateway '%s': %v", runGateway, err)

commands/top.go

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package commands
66

77
import (
88
"fmt"
9+
"os"
910
"os/exec"
1011
"strings"
1112

@@ -48,6 +49,9 @@ func runTop(cmd *types.Command, args []string) {
4849
}
4950

5051
// Resolve gateway
52+
if topGateway == "" {
53+
topGateway = os.Getenv("SCW_GATEWAY")
54+
}
5155
var gateway string
5256
if topGateway == serverID || topGateway == args[0] {
5357
gateway = ""

0 commit comments

Comments
 (0)