diff options
author | matthieu <matthieu.cneude@gmail.com> | 2021-04-23 14:12:00 +0200 |
---|---|---|
committer | matthieu <matthieu.cneude@gmail.com> | 2021-04-23 14:12:00 +0200 |
commit | 9c6bf55d4709e4ef31d60e58d22e7259f4d8a298 (patch) | |
tree | 0c0d170d714d82617942c66e07cdf5fb720b2275 | |
parent | cc4b469dd9afb2dab5b32aaec6d83560cb7ae088 (diff) |
Add command to edit a config
-rw-r--r-- | cmd/edit.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/cmd/edit.go b/cmd/edit.go new file mode 100644 index 0000000..755abe8 --- /dev/null +++ b/cmd/edit.go @@ -0,0 +1,37 @@ +package cmd + +import ( + "fmt" + "os" + "os/exec" + "path/filepath" + + "github.com/spf13/cobra" +) + +var editor string + +func editCmd() *cobra.Command { + editCmd := &cobra.Command{ + Use: "edit", + Short: "edit dashboard", + Run: func(cmd *cobra.Command, args []string) { + edit(args) + }, + } + + editCmd.Flags().StringVarP(&editor, "editor", "e", "$EDITOR", "Path of your favorite editor") + + return editCmd +} + +func edit(args []string) { + // TODO make it work for every OS + cmd := exec.Command(os.ExpandEnv(editor), filepath.Join(dashPath(), args[0])) + cmd.Stdin = os.Stdin + cmd.Stdout = os.Stdout + err := cmd.Run() + if err != nil { + fmt.Println(err) + } +} |