Skip to content

Commit

Permalink
support for linux, mac added
Browse files Browse the repository at this point in the history
  • Loading branch information
lakshyajain-0291 committed Sep 5, 2024
1 parent 30c835c commit 835977a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
13 changes: 4 additions & 9 deletions cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ func removeElements(slice []string, element string) []string {

func LoadConfig() (*ConfigData, error) {

homeDir, err := os.UserHomeDir()
configDir, err := GetConfigDir()
if err != nil {
return nil, err
}

configPath := filepath.Join(homeDir, "gencli\\.gencli-config.json")
configPath := filepath.Join(configDir, ".gencli-config.json")
file, err := os.Open(configPath)
if err != nil {
return nil, err
Expand All @@ -116,17 +116,12 @@ func LoadConfig() (*ConfigData, error) {

func SaveConfig(config *ConfigData) error {

homeDir, err := os.UserHomeDir()
configDir, err := GetConfigDir()
if err != nil {
return err
}

gencliDir := filepath.Join(homeDir, "gencli")
if err := os.MkdirAll(gencliDir, 0755); err != nil {
return err
}

configPath := filepath.Join(homeDir, "gencli\\.gencli-config.json")
configPath := filepath.Join(configDir, ".gencli-config.json")
file, err := os.Create(configPath)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions cli/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func GetConfigDir() (string, error) {
}

}

func LoadIndex() ([]fileinfo.FileInfo, error) {

configDir, err := GetConfigDir()
Expand Down
24 changes: 24 additions & 0 deletions fileinfo/fileinfo.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
package fileinfo

import (
"os"
"path/filepath"
"runtime"
"time"

"github.com/google/generative-ai-go/genai"
)

func GetConfigDir() (string, error) {
homedir, err := os.UserHomeDir()
if err != nil {
return "", err
}

switch runtime.GOOS {
case "windows":
configDir := filepath.Join(homedir, "Appdata", "Local", "gencli")
return configDir, nil
case "darwin":
configDir := filepath.Join(homedir, "Library", "Application Support", "gencli")
return configDir, nil
default:
configDir := filepath.Join(homedir, ".config", "gencli")
return configDir, nil

}

}

type FileInfo struct {
Id int `json:"id"`
Name string `json:"name"`
Expand Down
8 changes: 4 additions & 4 deletions fileinfo/hashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ func (hs *HashSet) Remove(hashString string) {
}

func (hs *HashSet) SaveToFile() error {
homeDir, err := os.UserHomeDir()
configDir, err := GetConfigDir()
if err != nil {
return err
}

hashesPath := filepath.Join(homeDir, "gencli\\.gencli-hashes.json")
hashesPath := filepath.Join(configDir, ".gencli-hashes.json")
file, err := os.Create(hashesPath)
if err != nil {
return err
Expand All @@ -64,12 +64,12 @@ func (hs *HashSet) SaveToFile() error {
}

func (hs *HashSet) LoadFromFile() error {
homeDir, err := os.UserHomeDir()
configDir, err := GetConfigDir()
if err != nil {
return err
}

hashesPath := filepath.Join(homeDir, "gencli\\.gencli-hashes.json")
hashesPath := filepath.Join(configDir, ".gencli-hashes.json")

file, err := os.Open(hashesPath)
if err != nil {
Expand Down

0 comments on commit 835977a

Please sign in to comment.