From c3574f51578a96b5b6e689000593621019965079 Mon Sep 17 00:00:00 2001 From: Dar-rius Date: Mon, 7 Nov 2022 22:51:03 +0000 Subject: [PATCH] look for the config the different os --- cmd/add.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/cmd/add.go b/cmd/add.go index 0db6a55..d1c02cb 100644 --- a/cmd/add.go +++ b/cmd/add.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "os" + "runtime" "github.com/fsnotify/fsnotify" "github.com/spf13/cobra" @@ -51,11 +52,20 @@ func addProjectActually(project *Project) { func addProject(project *Project) { //the environment variable is stored in a variable in order to create and find the path.json file in the directory where the app is located filEnv := os.Getenv("gproject") - _, errs := os.OpenFile(filEnv+"\\path.json", os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600) - if errs != nil { - panic(errs) - } + sys := runtime.GOOS + if sys == "linux" || sys == "darwin"{ + _, errs := os.OpenFile(filEnv+"path.json", os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600) + if errs != nil{ + log.Fatal(errs) + } + } else { + _, errs := os.OpenFile(filEnv+"\\path.json", os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600) + if errs != nil{ + log.Fatal(errs) + } + } + viper.SetConfigName("path") viper.SetConfigType("json") viper.AddConfigPath(filEnv)