From 23fd98b9faa9c1266fc1b0447e30694edaf68149 Mon Sep 17 00:00:00 2001 From: Vincent Composieux Date: Tue, 20 Aug 2019 08:15:39 +0200 Subject: [PATCH] Fixed config init/edition to be opened with a tool available on user OS --- cmd/edit.go | 4 ++-- cmd/init.go | 4 ++-- cmd/main.go | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/cmd/edit.go b/cmd/edit.go index afe7f454..0f85f8d5 100644 --- a/cmd/edit.go +++ b/cmd/edit.go @@ -28,10 +28,10 @@ in the source code repository.`, files = []string{config.Filepath} } - command := exec.Command("open", files...) + command := exec.Command(openerCommand, files...) if err := command.Start(); err != nil { - fmt.Printf("❌ Cannot run the 'open' command to edit config file: %v\n", err) + fmt.Printf("❌ Cannot run the '%s' command to edit config file: %v\n", openerCommand, err) return } }, diff --git a/cmd/init.go b/cmd/init.go index 779c50bc..d453da9f 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -23,10 +23,10 @@ in the source code repository.`, return } - command := exec.Command("open", config.Filepath) + command := exec.Command(openerCommand, config.Filepath) if err := command.Start(); err != nil { - fmt.Printf("❌ Cannot run the 'open' command to edit config file: %v\n", err) + fmt.Printf("❌ Cannot run the '%s' command to edit config file: %v\n", openerCommand, err) return } } else { diff --git a/cmd/main.go b/cmd/main.go index b0c84541..178fc2bb 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "os/signal" + "runtime" "syscall" "github.com/eko/monday/pkg/config" @@ -30,9 +31,13 @@ var ( forwarderComponent *forwarder.Forwarder runnerComponent *runner.Runner watcherComponent *watcher.Watcher + + openerCommand string ) func main() { + initRuntimeEnvironment() + rootCmd := &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { conf, err := config.Load() @@ -61,6 +66,16 @@ func main() { } } +func initRuntimeEnvironment() { + switch runtime.GOOS { + case "darwin": + openerCommand = "open" + + default: + openerCommand = "gedit" + } +} + func selectProject(conf *config.Config) string { prompt := promptui.Select{ Label: "Which project do you want to work on?",