Skip to content

Commit

Permalink
Merge pull request #14 from ulucinar/fix-7
Browse files Browse the repository at this point in the history
Allow command-line options for the editor to be specified via KUBE_EDITOR env. variable
  • Loading branch information
ulucinar authored Jan 23, 2022
2 parents 07d2b8f + dccb049 commit 5140e0d
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions cmd/edit_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func NewCmdEditStatus(streams genericclioptions.IOStreams) *cobra.Command {
}

// Init ensures that all required arguments and flag values are provided and fills the EditStatusOptions receiver arg
func (o *EditStatusOptions) Init(cmd *cobra.Command, args []string) error {
func (o *EditStatusOptions) Init(_ *cobra.Command, args []string) error {
switch len(args) {
case 2:
o.resource = args[0]
Expand Down Expand Up @@ -295,11 +295,26 @@ func (o *EditStatusOptions) storeResource(f *os.File) error {
}

func (o *EditStatusOptions) editResource(f *os.File) error {
cmd := exec.Command(o.resourceEditor, f.Name())
parts := strings.Fields(o.resourceEditor)
execName := ""
var args []string
switch len(parts) {
case 0:
return errors.Errorf("invalid editor specification: %q", o.resourceEditor)

default:
args = parts[1:]
fallthrough

case 1:
execName = parts[0]
args = append(args, f.Name())
}
cmd := exec.Command(execName, args...)
cmd.Stdin = o.In
cmd.Stdout = o.Out
cmd.Stderr = o.ErrOut
return errors.Wrapf(cmd.Run(), "cannot edit resource using editor: %q", o.resourceEditor)
return errors.Wrapf(cmd.Run(), "cannot edit resource using editor. Command-line: %q", cmd.String())
}

func (o *EditStatusOptions) writeResourceStatus(f *os.File) error {
Expand Down

0 comments on commit 5140e0d

Please sign in to comment.