From 99b210a088a55a43ccc1df0048e3bedadade69a5 Mon Sep 17 00:00:00 2001 From: Manfred Touron Date: Sat, 18 Jul 2015 16:00:47 +0200 Subject: [PATCH] Can now pass gateway var using environment (#70, #71) --- commands/cp.go | 6 ++++++ commands/exec.go | 3 +++ commands/kill.go | 3 +++ commands/logs.go | 5 +++++ commands/port.go | 5 +++++ commands/run.go | 3 +++ commands/top.go | 4 ++++ 7 files changed, 29 insertions(+) diff --git a/commands/cp.go b/commands/cp.go index 343323ed6e..bfe04110d6 100644 --- a/commands/cp.go +++ b/commands/cp.go @@ -84,6 +84,9 @@ func TarFromSource(apiClient *api.ScalewayAPI, source string) (*io.ReadCloser, e remoteCommand = append(remoteCommand, base) // Resolve gateway + if cpGateway == "" { + cpGateway = os.Getenv("SCW_GATEWAY") + } var gateway string if cpGateway == serverID || cpGateway == serverParts[0] { gateway = "" @@ -178,6 +181,9 @@ func UntarToDest(apiClient *api.ScalewayAPI, sourceStream *io.ReadCloser, destin remoteCommand = append(remoteCommand, "-xf", "-") // Resolve gateway + if cpGateway == "" { + cpGateway = os.Getenv("SCW_GATEWAY") + } var gateway string if cpGateway == serverID || cpGateway == serverParts[0] { gateway = "" diff --git a/commands/exec.go b/commands/exec.go index e9814bd7df..88dfa4eae3 100644 --- a/commands/exec.go +++ b/commands/exec.go @@ -58,6 +58,9 @@ func runExec(cmd *types.Command, args []string) { serverID := cmd.API.GetServerID(args[0]) // Resolve gateway + if execGateway == "" { + execGateway = os.Getenv("SCW_GATEWAY") + } var gateway string var err error if execGateway == serverID || execGateway == args[0] { diff --git a/commands/kill.go b/commands/kill.go index 0dc1b5b54a..af9af2c8f1 100644 --- a/commands/kill.go +++ b/commands/kill.go @@ -49,6 +49,9 @@ func runKill(cmd *types.Command, args []string) { } // Resolve gateway + if killGateway == "" { + killGateway = os.Getenv("SCW_GATEWAY") + } var gateway string if killGateway == serverID || killGateway == args[0] { gateway = "" diff --git a/commands/logs.go b/commands/logs.go index d11e6cf4d2..f5f66b1ad7 100644 --- a/commands/logs.go +++ b/commands/logs.go @@ -5,6 +5,8 @@ package commands import ( + "os" + log "github.com/Sirupsen/logrus" "github.com/scaleway/scaleway-cli/api" @@ -45,6 +47,9 @@ func runLogs(cmd *types.Command, args []string) { // FIXME: switch to serial history when API is ready // Resolve gateway + if logsGateway == "" { + logsGateway = os.Getenv("SCW_GATEWAY") + } var gateway string if logsGateway == serverID || logsGateway == args[0] { gateway = "" diff --git a/commands/port.go b/commands/port.go index 6a85fe99de..686f023a0b 100644 --- a/commands/port.go +++ b/commands/port.go @@ -5,6 +5,8 @@ package commands import ( + "os" + log "github.com/Sirupsen/logrus" "github.com/scaleway/scaleway-cli/api" @@ -43,6 +45,9 @@ func runPort(cmd *types.Command, args []string) { } // Resolve gateway + if portGateway == "" { + portGateway = os.Getenv("SCW_GATEWAY") + } var gateway string if portGateway == serverID || portGateway == args[0] { gateway = "" diff --git a/commands/run.go b/commands/run.go index 158503b0a3..d63c798092 100644 --- a/commands/run.go +++ b/commands/run.go @@ -101,6 +101,9 @@ func runRun(cmd *types.Command, args []string) { } } else { // Resolve gateway + if runGateway == "" { + runGateway = os.Getenv("SCW_GATEWAY") + } gateway, err := api.ResolveGateway(cmd.API, runGateway) if err != nil { log.Fatalf("Cannot resolve Gateway '%s': %v", runGateway, err) diff --git a/commands/top.go b/commands/top.go index 0e9cbd4023..0e39e5a68b 100644 --- a/commands/top.go +++ b/commands/top.go @@ -6,6 +6,7 @@ package commands import ( "fmt" + "os" "os/exec" "strings" @@ -48,6 +49,9 @@ func runTop(cmd *types.Command, args []string) { } // Resolve gateway + if topGateway == "" { + topGateway = os.Getenv("SCW_GATEWAY") + } var gateway string if topGateway == serverID || topGateway == args[0] { gateway = ""