feat
- configuration
This commit is contained in:
1 parent
281d7d76d4
commit
a8f164c241
4 files changed
+60
-3
No files matched your search
@@ -2,6 +2,13 @@
|
|||||||
|
|
||||||
## [Latest]
|
## [Latest]
|
||||||
|
|
||||||
|
## [0.2.0-alpha] - 2026-08-08
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Configuration options
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
|
||||||
## [0.1.0-alpha] - 2026-08-04
|
## [0.1.0-alpha] - 2026-08-04
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
## Table of contents
|
## Table of contents
|
||||||
- [Features](#features)
|
- [Features](#features)
|
||||||
- [Building from Source](#building-from-source)
|
- [Building from Source](#building-from-source)
|
||||||
|
- [Configuration](#configuration)
|
||||||
- [Usage](#usage)
|
- [Usage](#usage)
|
||||||
- [Upcoming Features](#upcoming-features)
|
- [Upcoming Features](#upcoming-features)
|
||||||
|
|
||||||
@@ -34,10 +35,20 @@ cd spellbook
|
|||||||
|
|
||||||
# Build static binary
|
# Build static binary
|
||||||
CGO_ENABLED=0 go build -o spellbook .
|
CGO_ENABLED=0 go build -o spellbook .
|
||||||
|
|
||||||
|
# Move to bin directory (for Linux/macOS)
|
||||||
|
mv spellbook $(go env GOPATH)/bin/
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
### Env
|
||||||
|
- `SPELLBOOK_DB_PATH`: db location (example: `/spellbook/spellbook.db`)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
- Use `spellbook help` to list commands
|
- Use `spellbook help` to list commands
|
||||||
@@ -95,5 +106,4 @@ spellbook my-spell target=127.0.0.1
|
|||||||
---
|
---
|
||||||
|
|
||||||
## Upcoming Features
|
## Upcoming Features
|
||||||
- Search to navigate your spell book
|
- Search to navigate your spell book
|
||||||
- Configuration
|
|
||||||
+9
-1
@@ -7,10 +7,12 @@ import (
|
|||||||
"github.com/abelith/spellbook/internal/adapters/caster"
|
"github.com/abelith/spellbook/internal/adapters/caster"
|
||||||
"github.com/abelith/spellbook/internal/adapters/sqlite"
|
"github.com/abelith/spellbook/internal/adapters/sqlite"
|
||||||
"github.com/abelith/spellbook/internal/application"
|
"github.com/abelith/spellbook/internal/application"
|
||||||
|
"github.com/abelith/spellbook/internal/config"
|
||||||
"github.com/abelith/spellbook/internal/controllers/cli"
|
"github.com/abelith/spellbook/internal/controllers/cli"
|
||||||
_ "modernc.org/sqlite"
|
_ "modernc.org/sqlite"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"path/filepath"
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -25,7 +27,13 @@ func main() {
|
|||||||
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
db, err := sql.Open("sqlite", "db.sql")
|
cfg, err := config.NewConfig()
|
||||||
|
handleErr(err)
|
||||||
|
|
||||||
|
dir := filepath.Dir(cfg.DBPath)
|
||||||
|
handleErr(os.MkdirAll(dir, 0755))
|
||||||
|
|
||||||
|
db, err := sql.Open("sqlite", cfg.DBPath)
|
||||||
handleErr(err)
|
handleErr(err)
|
||||||
|
|
||||||
repo := sqlite.NewRepo(db)
|
repo := sqlite.NewRepo(db)
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
DBPath string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewConfig() (*Config, error) {
|
||||||
|
dsn, err := getDBPath()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Config{DBPath: dsn}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getDBPath() (string, error) {
|
||||||
|
if dsn := os.Getenv("SPELLBOOK_DB_PATH"); dsn != "" {
|
||||||
|
return dsn, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
dir, err := os.UserConfigDir()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return filepath.Join(dir, "spellbook", "spellbook.db"), nil
|
||||||
|
}
|
||||||
Reference in new issue
Block a user