/
edit.go
39 lines (32 loc) · 982 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
package main
import (
"fmt"
"os/exec"
"github.com/eko/monday/internal/runtime"
"github.com/eko/monday/pkg/config"
"github.com/spf13/cobra"
)
var editCmd = &cobra.Command{
Use: "edit",
Short: "This command allows you to open the configuration file in your default editor",
Long: `For more information about the configuration, see the "example.yaml" file available
in the source code repository.`,
Run: func(cmd *cobra.Command, args []string) {
// Check for multiple configuration file
files := config.FindMultipleConfigFiles()
// Check for single configuration file
err := config.CheckConfigFileExists()
if err != nil {
fmt.Printf("❌ %v\n", err)
return
}
if len(files) == 0 {
files = []string{config.Filepath}
}
command := exec.Command(runtime.EditorCommand, files...)
if err := command.Start(); err != nil {
fmt.Printf("❌ Cannot run the '%s' command to edit config file: %v\n", runtime.EditorCommand, err)
return
}
},
}