Commit 5f8743ea authored by k8s-merge-robot's avatar k8s-merge-robot

Merge pull request #17108 from kargakis/fix-editor-env

Auto commit by PR queue bot
parents 39cabe35 523b6ec7
...@@ -17,8 +17,8 @@ Edit a resource from the default editor. ...@@ -17,8 +17,8 @@ Edit a resource from the default editor.
.PP .PP
The edit command allows you to directly edit any API resource you can retrieve via the The edit command allows you to directly edit any API resource you can retrieve via the
command line tools. It will open the editor defined by your KUBE\_EDITOR, GIT\_EDITOR, command line tools. It will open the editor defined by your KUBE\_EDITOR, or EDITOR
or EDITOR environment variables, or fall back to 'vi' for Linux or 'notepad' for Windows. environment variables, or fall back to 'vi' for Linux or 'notepad' for Windows.
You can edit multiple objects, although changes are applied one at a time. The command You can edit multiple objects, although changes are applied one at a time. The command
accepts filenames as well as command line arguments, although the files you point to must accepts filenames as well as command line arguments, although the files you point to must
be previously saved versions of resources. be previously saved versions of resources.
......
...@@ -41,8 +41,8 @@ Edit a resource on the server ...@@ -41,8 +41,8 @@ Edit a resource on the server
Edit a resource from the default editor. Edit a resource from the default editor.
The edit command allows you to directly edit any API resource you can retrieve via the The edit command allows you to directly edit any API resource you can retrieve via the
command line tools. It will open the editor defined by your KUBE_EDITOR, GIT_EDITOR, command line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR
or EDITOR environment variables, or fall back to 'vi' for Linux or 'notepad' for Windows. environment variables, or fall back to 'vi' for Linux or 'notepad' for Windows.
You can edit multiple objects, although changes are applied one at a time. The command You can edit multiple objects, although changes are applied one at a time. The command
accepts filenames as well as command line arguments, although the files you point to must accepts filenames as well as command line arguments, although the files you point to must
be previously saved versions of resources. be previously saved versions of resources.
......
...@@ -46,8 +46,8 @@ const ( ...@@ -46,8 +46,8 @@ const (
editLong = `Edit a resource from the default editor. editLong = `Edit a resource from the default editor.
The edit command allows you to directly edit any API resource you can retrieve via the The edit command allows you to directly edit any API resource you can retrieve via the
command line tools. It will open the editor defined by your KUBE_EDITOR, GIT_EDITOR, command line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR
or EDITOR environment variables, or fall back to 'vi' for Linux or 'notepad' for Windows. environment variables, or fall back to 'vi' for Linux or 'notepad' for Windows.
You can edit multiple objects, although changes are applied one at a time. The command You can edit multiple objects, although changes are applied one at a time. The command
accepts filenames as well as command line arguments, although the files you point to must accepts filenames as well as command line arguments, although the files you point to must
be previously saved versions of resources. be previously saved versions of resources.
...@@ -148,7 +148,7 @@ func RunEdit(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin ...@@ -148,7 +148,7 @@ func RunEdit(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
} }
windowsLineEndings := cmdutil.GetFlagBool(cmd, "windows-line-endings") windowsLineEndings := cmdutil.GetFlagBool(cmd, "windows-line-endings")
edit := editor.NewDefaultEditor() edit := editor.NewDefaultEditor(f.EditorEnvs())
defaultVersion := cmdutil.OutputVersionFromGroupVersion(cmd, clientConfig.GroupVersion) defaultVersion := cmdutil.OutputVersionFromGroupVersion(cmd, clientConfig.GroupVersion)
results := editResults{} results := editResults{}
for { for {
......
...@@ -53,8 +53,8 @@ type Editor struct { ...@@ -53,8 +53,8 @@ type Editor struct {
// the proper command line. If the provided editor has no spaces, or no quotes, // 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 // it is treated as a bare command to be loaded. Otherwise, the string will
// be passed to the user's shell for execution. // be passed to the user's shell for execution.
func NewDefaultEditor() Editor { func NewDefaultEditor(envs []string) Editor {
args, shell := defaultEnvEditor() args, shell := defaultEnvEditor(envs)
return Editor{ return Editor{
Args: args, Args: args,
Shell: shell, Shell: shell,
...@@ -73,8 +73,16 @@ func defaultEnvShell() []string { ...@@ -73,8 +73,16 @@ func defaultEnvShell() []string {
return []string{shell, flag} return []string{shell, flag}
} }
func defaultEnvEditor() ([]string, bool) { func defaultEnvEditor(envs []string) ([]string, bool) {
editor := os.Getenv("EDITOR") var editor string
for _, env := range envs {
if len(env) > 0 {
editor = os.Getenv(env)
}
if len(editor) > 0 {
break
}
}
if len(editor) == 0 { if len(editor) == 0 {
editor = platformize(defaultEditor, windowsEditor) editor = platformize(defaultEditor, windowsEditor)
} }
......
...@@ -101,6 +101,10 @@ type Factory struct { ...@@ -101,6 +101,10 @@ type Factory struct {
CanBeAutoscaled func(kind string) error CanBeAutoscaled func(kind string) error
// AttachablePodForObject returns the pod to which to attach given an object. // AttachablePodForObject returns the pod to which to attach given an object.
AttachablePodForObject func(object runtime.Object) (*api.Pod, error) AttachablePodForObject func(object runtime.Object) (*api.Pod, error)
// EditorEnvs returns a group of environment variables that the edit command
// can range over in order to determine if the user has specified an editor
// of their choice.
EditorEnvs func() []string
} }
// NewFactory creates a factory with the default Kubernetes resources defined // NewFactory creates a factory with the default Kubernetes resources defined
...@@ -331,6 +335,9 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory { ...@@ -331,6 +335,9 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
return nil, fmt.Errorf("cannot attach to %s: not implemented", kind) return nil, fmt.Errorf("cannot attach to %s: not implemented", kind)
} }
}, },
EditorEnvs: func() []string {
return []string{"KUBE_EDITOR", "EDITOR"}
},
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment