Skip to content

Commit

Permalink
Add database_file_path option
Browse files Browse the repository at this point in the history
  • Loading branch information
piqoni committed May 9, 2023
1 parent ec710af commit 796dccc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
17 changes: 7 additions & 10 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"database/sql"
"encoding/xml"
"errors"
"flag"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -173,17 +172,15 @@ func bootstrapConfig() {
terminal_mode = viper.GetBool("terminal_mode")
}

dbPath, err := os.UserConfigDir()
check(err)

if _, err := os.Stat(dbPath + "/brew"); errors.Is(err, os.ErrNotExist) {
err := os.Mkdir(dbPath+"/brew", os.ModePerm)
if err != nil {
check(err)
}
databaseFilePath := viper.GetString("database_file_path")
if databaseFilePath == "" {
databaseDirPath, err := os.UserConfigDir()
check(err)
databaseFilePath = filepath.Join(databaseDirPath, "brew", "matcha.db")
check(os.MkdirAll(filepath.Dir(databaseFilePath), os.ModePerm))
}

db, err = sql.Open("sqlite", dbPath+"/brew/matcha.db")
db, err = sql.Open("sqlite", databaseFilePath)
check(err)
err = applyMigrations(db)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion feeds_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type RSS struct {

func check(e error) {
if e != nil {
panic(e)
log.Fatal(e)
}
}

Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ go 1.18

require (
github.com/mmcdole/gofeed v1.1.3
github.com/sashabaranov/go-openai v1.9.0
github.com/spf13/viper v1.12.0
modernc.org/sqlite v1.20.0
)

require (
github.com/go-shiori/dom v0.0.0-20210627111528-4e4722cd0d65 // indirect
github.com/gogs/chardet v0.0.0-20191104214054-4b6791f73a28 // indirect
github.com/sashabaranov/go-openai v1.9.0 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
)

Expand All @@ -34,7 +34,6 @@ require (
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
github.com/sashabaranov/go-gpt3 v1.0.1
github.com/savioxavier/termlink v1.2.1
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/cast v1.5.0 // indirect
Expand Down

0 comments on commit 796dccc

Please sign in to comment.