From 2ebc04042575e4a4c128caaffbac26e7a763ac75 Mon Sep 17 00:00:00 2001 From: nnao45 Date: Mon, 8 Jul 2019 17:58:41 +0900 Subject: [PATCH] Patch/delete double whitespace (#118) * imple DeleteDoubleWhiteSpace * fix blank check --- pkg/execute/executor.go | 6 ++++-- pkg/utils/utils.go | 11 +++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pkg/execute/executor.go b/pkg/execute/executor.go index 928591931..d629f6291 100644 --- a/pkg/execute/executor.go +++ b/pkg/execute/executor.go @@ -3,7 +3,6 @@ package execute import ( "bytes" "fmt" - "gopkg.in/yaml.v2" "io/ioutil" "os" "os/exec" @@ -13,9 +12,12 @@ import ( "text/tabwriter" "unicode" + "gopkg.in/yaml.v2" + "github.com/infracloudio/botkube/pkg/config" filterengine "github.com/infracloudio/botkube/pkg/filterengine" log "github.com/infracloudio/botkube/pkg/logging" + "github.com/infracloudio/botkube/pkg/utils" ) var validKubectlCommands = map[string]bool{ @@ -178,7 +180,7 @@ func trimQuotes(clusterValue string) string { func runKubectlCommand(args []string, clusterName string, isAuthChannel bool) string { // Use 'default' as a default namespace - args = append([]string{"-n", "default"}, args...) + args = append([]string{"-n", "default"}, utils.DeleteDoubleWhiteSpace(args)...) // Remove unnecessary flags finalArgs := []string{} diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 703535abd..3d7c18e9c 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -225,3 +225,14 @@ func GetObjectTypeMetaData(obj interface{}) metaV1.TypeMeta { } return typeMeta } + +// DeleteDoubleWhiteSpace returns slice that removing whitespace from a arg slice +func DeleteDoubleWhiteSpace(slice []string) []string { + result := []string{} + for _, s := range slice { + if len(s) != 0 { + result = append(result, s) + } + } + return result +}