Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message when diff binary is not in PATH #87344

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions staging/src/k8s.io/kubectl/pkg/cmd/diff/diff.go
Expand Up @@ -130,7 +130,7 @@ type DiffProgram struct {
genericclioptions.IOStreams
}

func (d *DiffProgram) getCommand(args ...string) exec.Cmd {
func (d *DiffProgram) getCommand(args ...string) (string, exec.Cmd) {
diff := ""
if envDiff := os.Getenv("KUBECTL_EXTERNAL_DIFF"); envDiff != "" {
diff = envDiff
Expand All @@ -143,12 +143,16 @@ func (d *DiffProgram) getCommand(args ...string) exec.Cmd {
cmd.SetStdout(d.Out)
cmd.SetStderr(d.ErrOut)

return cmd
return diff, cmd
}

// Run runs the detected diff program. `from` and `to` are the directory to diff.
func (d *DiffProgram) Run(from, to string) error {
return d.getCommand(from, to).Run()
diff, cmd := d.getCommand(from, to)
if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to run %q: %v", diff, err)
}
return nil
}

// Printer is used to print an object.
Expand Down