From 9162fce5c0229d69f00dd1df6e11039e1e99fb8e Mon Sep 17 00:00:00 2001 From: Jose Rojas <39174181+jarojasm95@users.noreply.github.com> Date: Wed, 21 Jul 2021 13:15:26 -0600 Subject: [PATCH 1/3] KUBE_EDITOR --- pkg/editor/editor.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/editor/editor.go b/pkg/editor/editor.go index 426d5eb..760b464 100644 --- a/pkg/editor/editor.go +++ b/pkg/editor/editor.go @@ -10,9 +10,12 @@ const defaultEditor = "vi" //Edit opens the editor func Edit(file string) error { - editorFromEnv := os.Getenv("EDITOR") + editorFromEnv := os.Getenv("KUBE_EDITOR") if editorFromEnv == "" { - editorFromEnv = defaultEditor + editorFromEnv = os.Getenv("EDITOR") + if editorFromEnv == "" { + editorFromEnv = defaultEditor + } } command, args := getCommandAndArgs(editorFromEnv, file) From 2b36e229f2721626ab1042136e6657b62d95451d Mon Sep 17 00:00:00 2001 From: Jose Rojas <39174181+jarojasm95@users.noreply.github.com> Date: Thu, 12 Aug 2021 01:51:18 -0600 Subject: [PATCH 2/3] move to function --- pkg/editor/editor.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/editor/editor.go b/pkg/editor/editor.go index 760b464..9875b5e 100644 --- a/pkg/editor/editor.go +++ b/pkg/editor/editor.go @@ -8,8 +8,7 @@ import ( const defaultEditor = "vi" -//Edit opens the editor -func Edit(file string) error { +func getEditor() string { editorFromEnv := os.Getenv("KUBE_EDITOR") if editorFromEnv == "" { editorFromEnv = os.Getenv("EDITOR") @@ -17,8 +16,13 @@ func Edit(file string) error { editorFromEnv = defaultEditor } } + return editorFromEnv +} + +//Edit opens the editor +func Edit(file string) error { - command, args := getCommandAndArgs(editorFromEnv, file) + command, args := getCommandAndArgs(getEditor(), file) cmd := exec.Command(command, args...) cmd.Stdin = os.Stdin From 218cede0edbe2aa1e844c92aded3c38ac484c95f Mon Sep 17 00:00:00 2001 From: Jose Rojas <39174181+jarojasm95@users.noreply.github.com> Date: Sat, 14 Aug 2021 17:24:58 -0600 Subject: [PATCH 3/3] readability --- pkg/editor/editor.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/editor/editor.go b/pkg/editor/editor.go index 9875b5e..d90b682 100644 --- a/pkg/editor/editor.go +++ b/pkg/editor/editor.go @@ -9,14 +9,15 @@ import ( const defaultEditor = "vi" func getEditor() string { - editorFromEnv := os.Getenv("KUBE_EDITOR") - if editorFromEnv == "" { - editorFromEnv = os.Getenv("EDITOR") - if editorFromEnv == "" { - editorFromEnv = defaultEditor - } + if os.Getenv("KUBE_EDITOR") != "" { + return os.Getenv("KUBE_EDITOR") } - return editorFromEnv + + if os.Getenv("EDITOR") != "" { + return os.Getenv("EDITOR") + } + + return defaultEditor } //Edit opens the editor