Skip to content

Commit

Permalink
look for the config the different os
Browse files Browse the repository at this point in the history
  • Loading branch information
Dar-rius committed Nov 7, 2022
1 parent b351d04 commit c3574f5
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"
"os"
"runtime"

"github.com/fsnotify/fsnotify"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c3574f5

Please sign in to comment.