lots of changes and reducing dependency imports

This commit is contained in:
Robin Olsen
2026-02-28 16:39:50 +01:00
parent 697b17e890
commit ba0115d1bc
54 changed files with 458 additions and 327 deletions

32
internal/models/app.go Normal file
View File

@@ -0,0 +1,32 @@
package models
import (
"context"
"log/slog"
"github.com/steveyegge/beads"
)
type App struct {
Config Config
Issues IssueService
Stats StatsService
Logger *slog.Logger
Tasks *map[string]Tasker
Interfaces *map[string]Interface
CurrentFeedback *ValidationFeedback
}
type IssueService interface {
beads.Storage // Want to get rid of this dependency, but it provides a lot of useful methods that would be a pain to re-implement right now
DeleteIssues() error
}
type StatsService interface {
Load(ctx context.Context) error
Save(ctx context.Context) error
GetStatistics() (Statistics, error)
}

49
internal/models/config.go Normal file
View File

@@ -0,0 +1,49 @@
package models
type Config struct {
AutoInit bool
RootCmd string
WebAddress string
BeadsDBPath string
IssuePrefix string
StatisticsStoragePath string
}
var BaseConfig = Config{
AutoInit: false,
RootCmd: "pm",
IssuePrefix: "pm",
WebAddress: ":8080",
BeadsDBPath: "./.pm/db.db",
StatisticsStoragePath: "./.pm/stats.json",
}
func (c Config) WithAutoInit(autoInit bool) Config {
c.AutoInit = autoInit
return c
}
func (c Config) WithRootCmd(rootCmd string) Config {
c.RootCmd = rootCmd
return c
}
func (c Config) WithWebAddress(webAddress string) Config {
c.WebAddress = webAddress
return c
}
func (c Config) WithBeadsDBPath(beadsDBPath string) Config {
c.BeadsDBPath = beadsDBPath
return c
}
func (c Config) WithIssuePrefix(issuePrefix string) Config {
c.IssuePrefix = issuePrefix
return c
}
func (c Config) WithStatisticsStoragePath(path string) Config {
c.StatisticsStoragePath = path
return c
}

View File

@@ -0,0 +1,5 @@
package models
import "fmt"
var ErrUserQuit = fmt.Errorf("user quit")

View File

@@ -0,0 +1,21 @@
package models
import "context"
// Interface represents a user interface for interacting with the application.
// It can be any implementation that fulfills the Run method.
type Interface interface {
Run(context.Context, Config) error
}
// InterfaceType represents the type of user interface
type InterfaceType string
// Interface represents a user interface for interacting with the application.
// Keep lower case to avoid confusion with Go's built-in interfaces.
const (
InterfaceTypeCLI InterfaceType = "cli"
InterfaceTypeTUI InterfaceType = "tui"
InterfaceTypeWeb InterfaceType = "web"
InterfaceTypeREPL InterfaceType = "repl"
)

View File

@@ -2,19 +2,10 @@ package models
import (
"time"
"github.com/google/uuid"
)
type InterfaceType string
const (
InterfaceTypeCLI InterfaceType = "CLI"
InterfaceTypeWeb InterfaceType = "Web"
)
type Statistics struct {
ID uuid.UUID `json:"id"`
ID int `json:"id"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
Duration time.Duration `json:"duration"`

67
internal/models/task.go Normal file
View File

@@ -0,0 +1,67 @@
package models
import (
"context"
"github.com/charmbracelet/huh"
)
type Tasker interface {
Config() Config
Details() TaskDetails
Setup(context.Context) error
Questions(InterfaceType) Questions
Validate(context.Context) ValidationFeedback
}
type ValidationFeedback struct {
Success bool
Message string
Checks []Check
}
type Check struct {
Message string
Valid bool
}
type ValidatedInterface interface {
Interface
SetChannels(feedbackChan chan ValidationFeedback, quitChan chan bool)
}
type TaskDetails struct {
Title string
Description string
TimeToComplete string
Difficulty string
}
func (td TaskDetails) WithTitle(title string) TaskDetails {
td.Title = title
return td
}
func (td TaskDetails) WithDescription(description string) TaskDetails {
td.Description = description
return td
}
func (td TaskDetails) WithTimeToComplete(time string) TaskDetails {
td.TimeToComplete = time
return td
}
func (td TaskDetails) WithDifficulty(difficulty string) TaskDetails {
td.Difficulty = difficulty
return td
}
type Questions []*huh.Group
func (q Questions) With(group *huh.Group) Questions {
if group == nil {
return q
}
return append(q, group)
}