Skip to content

Commit

Permalink
Fixed config init/edition to be opened with a tool available on user OS
Browse files Browse the repository at this point in the history
  • Loading branch information
eko committed Aug 20, 2019
1 parent 0b83f57 commit 23fd98b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions cmd/edit.go
Expand Up @@ -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
}
},
Expand Down
4 changes: 2 additions & 2 deletions cmd/init.go
Expand Up @@ -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 {
Expand Down
15 changes: 15 additions & 0 deletions cmd/main.go
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"os/signal"
"runtime"
"syscall"

"github.com/eko/monday/pkg/config"
Expand All @@ -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()
Expand Down Expand Up @@ -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?",
Expand Down

0 comments on commit 23fd98b

Please sign in to comment.