mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 23:47:50 +00:00
edit: Make environment variables composable
It also adds support for KUBE_EDITOR and GIT_EDITOR which were already advertised in the edit usage message.
This commit is contained in:
committed by
Michail Kargakis
parent
a7425bf070
commit
523b6ec7e3
@@ -53,8 +53,8 @@ type Editor struct {
|
||||
// the proper command line. If the provided editor has no spaces, or no quotes,
|
||||
// it is treated as a bare command to be loaded. Otherwise, the string will
|
||||
// be passed to the user's shell for execution.
|
||||
func NewDefaultEditor() Editor {
|
||||
args, shell := defaultEnvEditor()
|
||||
func NewDefaultEditor(envs []string) Editor {
|
||||
args, shell := defaultEnvEditor(envs)
|
||||
return Editor{
|
||||
Args: args,
|
||||
Shell: shell,
|
||||
@@ -73,8 +73,16 @@ func defaultEnvShell() []string {
|
||||
return []string{shell, flag}
|
||||
}
|
||||
|
||||
func defaultEnvEditor() ([]string, bool) {
|
||||
editor := os.Getenv("EDITOR")
|
||||
func defaultEnvEditor(envs []string) ([]string, bool) {
|
||||
var editor string
|
||||
for _, env := range envs {
|
||||
if len(env) > 0 {
|
||||
editor = os.Getenv(env)
|
||||
}
|
||||
if len(editor) > 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if len(editor) == 0 {
|
||||
editor = platformize(defaultEditor, windowsEditor)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user