add promt to user to confirm initializaton in direcory

This commit is contained in:
Robin Olsen
2026-02-05 15:53:15 +01:00
parent d6884b6ac5
commit 2215b5ad34

View File

@@ -2,10 +2,13 @@ package service
import ( import (
"context" "context"
"fmt"
"os"
"time" "time"
"github.com/LazyBachelor/LazyPM/internal/models" "github.com/LazyBachelor/LazyPM/internal/models"
"github.com/LazyBachelor/LazyPM/internal/storage" "github.com/LazyBachelor/LazyPM/internal/storage"
"github.com/charmbracelet/huh"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/steveyegge/beads" "github.com/steveyegge/beads"
@@ -28,6 +31,11 @@ type Services struct {
func NewServices(ctx context.Context, config Config) (*Services, func(), error) { func NewServices(ctx context.Context, config Config) (*Services, func(), error) {
var cleanupFuncs []func() var cleanupFuncs []func()
if !initialized(config.BeadsDBPath) {
fmt.Println("PM is not initialized")
os.Exit(0)
}
store, err := beads.NewSQLiteStorage(ctx, config.BeadsDBPath) store, err := beads.NewSQLiteStorage(ctx, config.BeadsDBPath)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@@ -63,3 +71,24 @@ func runCleanup(funcs []func()) {
fn() fn()
} }
} }
func initialized(beadsPath string) bool {
_, err := os.Stat(beadsPath)
if os.IsNotExist(err) {
var initialize bool
huh.NewForm(
huh.NewGroup(
huh.NewConfirm().Title("PM is not initialized in this directory!").
Description("Do you want to initialize it here?").
Value(&initialize),
),
).WithTheme(huh.ThemeBase16()).WithAccessible(true).Run()
if !initialize {
return false
}
}
return true
}