forked from helm/helm-classic
/
edit.go
43 lines (34 loc) · 956 Bytes
/
edit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package action
import (
"os"
"os/exec"
"github.com/helm/helm/log"
"github.com/helm/helm/util"
)
// Edit charts using the shell-defined $EDITOR
//
// - chartName being edited
// - homeDir is the helm home directory for the user
func Edit(chartName, homeDir string) {
chartDir := util.WorkspaceChartDirectory(homeDir, chartName)
if _, err := os.Stat(chartDir); os.IsNotExist(err) {
log.Die("Could not find chart: %s", chartName)
}
openEditor(chartDir)
}
// openEditor opens the given filename in an interactive editor
func openEditor(path string) {
editor := os.Getenv("EDITOR")
if editor == "" {
log.Die("must set shell $EDITOR")
}
editorPath, err := exec.LookPath(editor)
if err != nil {
log.Die("Could not find %s in PATH", editor)
}
cmd := exec.Command(editorPath, path)
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
if err := cmd.Run(); err != nil {
log.Die("Could not open $EDITOR: %s", err)
}
}