Skip to content

Commit c3574f5

Browse files
committed
look for the config the different os
1 parent b351d04 commit c3574f5

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

cmd/add.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"log"
66
"os"
7+
"runtime"
78

89
"github.com/fsnotify/fsnotify"
910
"github.com/spf13/cobra"
@@ -51,11 +52,20 @@ func addProjectActually(project *Project) {
5152
func addProject(project *Project) {
5253
//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
5354
filEnv := os.Getenv("gproject")
54-
_, errs := os.OpenFile(filEnv+"\\path.json", os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
55-
if errs != nil {
56-
panic(errs)
57-
}
55+
sys := runtime.GOOS
56+
if sys == "linux" || sys == "darwin"{
57+
_, errs := os.OpenFile(filEnv+"path.json", os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
58+
if errs != nil{
59+
log.Fatal(errs)
60+
}
61+
} else {
62+
_, errs := os.OpenFile(filEnv+"\\path.json", os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
63+
if errs != nil{
64+
log.Fatal(errs)
65+
}
5866

67+
}
68+
5969
viper.SetConfigName("path")
6070
viper.SetConfigType("json")
6171
viper.AddConfigPath(filEnv)

0 commit comments

Comments
 (0)