Skip to content

Commit

Permalink
final debugs in file creation
Browse files Browse the repository at this point in the history
  • Loading branch information
lakshyajain-0291 committed Sep 26, 2024
2 parents 835977a + 7205b16 commit f66dc11
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 162 deletions.
67 changes: 26 additions & 41 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com

# The lines below are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/need to use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

version: 2

before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...

builds:
- main: ./main
- main: ./main.go
id: "gencli"
binary: ./bin/gencli
env:
Expand All @@ -29,29 +14,26 @@ builds:
{{- if eq .Os "windows" }}
{{- if eq .Arch "amd64" }}CC=x86_64-w64-mingw32-gcc{{- end }}
{{- end }}
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
flags:
- -mod=vendor
ldflags:
- -X github.com/AISocietyIITJ/gencli/pkg.Version={{ .Version }}
igmore:
- -X github.com/lakshyajain-0291/gencli/pkg.Version={{ .Version }}
ignore:
- goos: windows
- goarch: arm64

checksums:
checksum:
name_template: "checksums.txt"

nfpms:
- package_name: gencli
vendor: AISocietyIITJ
homepage: https://github.com/AISocietyIITJ/gencli
vendor: lakshyajain-0291
homepage: https://github.com/lakshyajain-0291/gencli
maintainer: Lakshya Jain <[email protected]>
license: MIT
formats:
Expand All @@ -69,21 +51,13 @@ nfpms:
release:
prerelease: auto
github:
owner: AISocietyIITJ
owner: lakshyajain-0291
name: gencli
name_template: "{{.ProjectName}}-v{{.Version}}"

archives:
- wrap_in_directory: false
format_overrides:
- goos: windows
format: zip
files:
- LICENSE
- README.md
aurs:
- name: gencli-bin
homepage: https://github.com/AISocietyIITJ/gencli
homepage: https://github.com/lakshyajain-0291/gencli
description: "GenCLI - A Gemini-Powered interactable CLI for fast, accurate file search."
license: MIT
maintainers:
Expand All @@ -102,39 +76,50 @@ aurs:
brews:
- name: gencli
url_template: "https://github.com/AISocietyIITJ/gencli/releases/download/{{ .Tag }}/{{ .ArtifactName }}"
url_template: "https://github.com/lakshyajain-0291/gencli/releases/download/{{ .Tag }}/{{ .ArtifactName }}"
download_strategy: CurlDownloadStrategy
commit_author:
name: lakshyajain-0291
email: [email protected]
commit_msg_template: "Brew formula update for gencli version {{ .Tag }}"
homepage: "https://github.com/AISocietyIITJ/gencli"
homepage: "https://github.com/lakshyajain-0291/gencli"
description: "GenCLI - A Gemini-Powered interactable CLI for fast, accurate file search."
license: "MIT"
skip_upload: false
install: |
bin.install "bin/gencli"
repository:
owner: AISocietyIITJ
owner: lakshyajain-0291
name: homebrew-gencli
branch: main
pull_request:
enabled: false

archives:
- format: zip
name_template: "{{ .Binary }}_{{ .Tag }}_{{ .Os }}_{{ .Arch }}"
files:
- LICENSE
- README.md
format_overrides:
- goos: windows
format: zip
id: windows-archive

scoops:
- name: gencli
url_template: "https://github.com/AISocietyIITJ/gencli/releases/download/{{ .Tag }}/{{ .ArtifactName }}"
url_template: "https://github.com/lakshyajain-0291/gencli/releases/download/{{ .Tag }}/{{ .ArtifactName }}"
commit_author:
name: lakshyajain-0291
email: [email protected]
commit_msg_template: "Scoop update for {{ .ProjectName }} version {{ .Tag }}"
homepage: "https://github.com/AISocietyIITJ/gencli"
homepage: "https://github.com/lakshyajain-0291/gencli"
description: "GenCLI - A Gemini-Powered interactable CLI for fast, accurate file search."
license: MIT
skip_upload: false
repository:
owner: AISocietyIITJ
owner: lakshyajain-0291
name: scoop-gencli
branch: main
pull_request:
enabled: false
enabled: false
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Lakshya Jain

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ A gemini powered interactable CLI tool that keeps record of all your files and c

3. Set up your Gemini API Keys :
```bash
./gencli config --add-apikeys "<your-api-key-1>","<your-api-key-1>"
./gencli config --add-apikeys "<your-api-key-1>","<your-api-key-2>"
```

4. Set up directories to Index :
Expand Down Expand Up @@ -164,4 +164,4 @@ Contributions are welcome! Fork the repository and submit a pull request.
## License


---
---
32 changes: 23 additions & 9 deletions cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,26 @@ func setConfig(addDirectories, deleteDirectories, addSkipTypes, deleteSkipTypes,
config, err := LoadConfig()
if err != nil {
if errors.Is(err, os.ErrNotExist) {
// if no addDirectories are provided adds current working directory (can also change this to root directory of system)
if len(addDirectories) == 0 {
cwd, err := os.Getwd()
if err != nil {
return fmt.Errorf("failed to get working directory : %w", err)
return fmt.Errorf("failed to get working directory: %w", err)
}
addDirectories = append(addDirectories, cwd)
}

config = &ConfigData{}

} else {
return err
}
}

if len(addDirectories) > 0 {
config.Directories = append(config.Directories, addDirectories...)
for _, dir := range addDirectories {
if _, err := os.Stat(dir); os.IsNotExist(err) {
return fmt.Errorf("directory does not exist: %s", dir)
}
if !contains(config.Directories, dir) {
config.Directories = append(config.Directories, dir)
}
}

for _, dir := range deleteDirectories {
Expand All @@ -62,8 +64,10 @@ func setConfig(addDirectories, deleteDirectories, addSkipTypes, deleteSkipTypes,
config.SkipFile = removeElements(config.SkipFile, fileName)
}

if len(addAPIKeys) > 0 {
config.APIKeys = append(config.APIKeys, addAPIKeys...)
for _, apiKey := range addAPIKeys {
if !contains(config.APIKeys, apiKey) {
config.APIKeys = append(config.APIKeys, apiKey)
}
}

for _, api := range deleteAPIKeys {
Expand All @@ -75,13 +79,23 @@ func setConfig(addDirectories, deleteDirectories, addSkipTypes, deleteSkipTypes,
}

if err := SaveConfig(config); err != nil {
return fmt.Errorf("failed to save config : %w", err)
return fmt.Errorf("failed to save config: %w", err)
}

fmt.Println(fileinfo.Green("Configurations Saved Successfully"))
return nil
}

// Helper function to check if a slice contains a specific string
func contains(slice []string, item string) bool {
for _, v := range slice {
if v == item {
return true
}
}
return false
}

func removeElements(slice []string, element string) []string {
for i, v := range slice {
if v == element {
Expand Down
17 changes: 11 additions & 6 deletions cli/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,24 @@ func GetConfigDir() (string, error) {
return "", err
}

var configDir string

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

}

err = os.MkdirAll(configDir, 0755)
if err != nil {
return "", err
}

return configDir, nil
}

func LoadIndex() ([]fileinfo.FileInfo, error) {
Expand Down
17 changes: 11 additions & 6 deletions fileinfo/fileinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,24 @@ func GetConfigDir() (string, error) {
return "", err
}

var configDir string

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

}

err = os.MkdirAll(configDir, 0755)
if err != nil {
return "", err
}

return configDir, nil
}

type FileInfo struct {
Expand Down
5 changes: 0 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,12 @@ require (
github.com/charmbracelet/lipgloss v0.12.1 // indirect
github.com/charmbracelet/x/ansi v0.1.4 // indirect
github.com/dlclark/regexp2 v1.11.0 // indirect
github.com/gdamore/encoding v1.0.0 // indirect
github.com/gdamore/tcell/v2 v2.7.1 // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/microcosm-cc/bluemonday v1.0.27 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/rivo/tview v0.0.0-20240807205129-e4c497cc59ed // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/yuin/goldmark v1.7.4 // indirect
github.com/yuin/goldmark-emoji v1.0.3 // indirect
Expand All @@ -43,7 +39,6 @@ require (
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/generative-ai-go v0.16.0
github.com/google/s2a-go v0.1.8 // indirect
github.com/google/uuid v1.6.0 // indirect
Expand Down
Loading

0 comments on commit f66dc11

Please sign in to comment.