Files
spellbook/cmd/main.go
T
abelith 4447b7343f feat: search cmd
chore: raw sql replaced with squirrel
fix: -n is now required for add cmd
2026-08-15 18:38:26 +05:00

53 lines
1.1 KiB
Go

package main
import (
"context"
"database/sql"
"fmt"
"github.com/abelith/spellbook/internal/adapters/caster"
"github.com/abelith/spellbook/internal/adapters/sqlite"
"github.com/abelith/spellbook/internal/application"
"github.com/abelith/spellbook/internal/config"
"github.com/abelith/spellbook/internal/controllers/cli"
_ "modernc.org/sqlite"
"os"
"os/signal"
"path/filepath"
"syscall"
)
// Version is set on build via -ldflags
var Version = "dev"
func handleErr(err error) {
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func main() {
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer cancel()
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)
repo := sqlite.NewRepo(db)
handleErr(repo.Init(ctx))
app := application.NewApplication(&caster.SpellCaster{}, repo, repo)
c := cli.NewCLI(Version, app)
if err := c.Run(ctx); err != nil {
os.Exit(1)
}
}