edit command

This commit is contained in:
2020-08-13 21:37:29 -04:00
parent 47a184b89c
commit 71216306da
2 changed files with 68 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import (
"path/filepath"
"regexp"
"strings"
"syscall"
"github.com/mitchellh/go-homedir"
"gopkg.in/yaml.v2"
@ -133,6 +134,27 @@ func NewProject(name string) error {
return project.Save()
}
func EditProject(name string) error {
fileName := getConfigFilePath(name)
_, err := os.Stat(fileName)
if err != nil {
return errors.New("Config file does not exist")
}
editorName := os.Getenv("EDITOR")
if editorName == "" {
return errors.New("EDITOR variable not defined")
}
editor, err := exec.LookPath(editorName)
if err != nil {
return err
}
return syscall.Exec(editor, []string{editorName, fileName}, os.Environ())
}
func (p *Project) Save() error {
fileName := getConfigFilePath(p.Name)