refactor survery cmd

move package files to pkg
This commit is contained in:
Robin Olsen
2026-02-13 10:13:41 +01:00
parent fc5156a0ad
commit e994c890f4
11 changed files with 23 additions and 38 deletions

View File

@@ -6,6 +6,7 @@ import (
"github.com/LazyBachelor/LazyPM/cmd/survey/tasks"
"github.com/LazyBachelor/LazyPM/internal/service"
"github.com/LazyBachelor/LazyPM/pkg/cli/repl"
"github.com/LazyBachelor/LazyPM/pkg/task"
"github.com/LazyBachelor/LazyPM/pkg/tui"
"github.com/LazyBachelor/LazyPM/pkg/web"
)
@@ -20,13 +21,13 @@ func initializeServices(ctx context.Context) (*service.Services, func(), error)
return service.NewServices(ctx, config)
}
func initTasks() []*tasks.Task {
return []*tasks.Task{
func initTasks() []*task.Task {
return []*task.Task{
tasks.NewCreateIssueTask(),
tasks.NewCreateIssueTask(),
}
}
func initInterfaces() []tasks.Interface {
return []tasks.Interface{repl.NewRepl(), tui.NewTui(), web.NewWeb()}
func initInterfaces() []task.Interface {
return []task.Interface{repl.NewRepl(), tui.NewTui(), web.NewWeb()}
}

View File

@@ -5,14 +5,12 @@ import (
"fmt"
"log"
"math/rand"
"time"
"github.com/LazyBachelor/LazyPM/cmd/survey/tasks"
"github.com/LazyBachelor/LazyPM/internal/service"
"github.com/LazyBachelor/LazyPM/pkg/task"
)
func main() {
rand.Seed(time.Now().UnixNano())
ctx := context.Background()
svc, close, err := initializeServices(ctx)
@@ -29,7 +27,7 @@ func main() {
}
}
func taskLoop(ctx context.Context, svc *service.Services, surveyTasks []*tasks.Task, interfaces []tasks.Interface) error {
func taskLoop(ctx context.Context, svc *service.Services, surveyTasks []*task.Task, interfaces []task.Interface) error {
interfaceIndex := rand.Int() % len(interfaces)
for _, task := range surveyTasks {

View File

@@ -4,25 +4,26 @@ import (
"context"
"errors"
"github.com/LazyBachelor/LazyPM/cmd/survey/ui"
"github.com/LazyBachelor/LazyPM/internal/models"
"github.com/LazyBachelor/LazyPM/internal/service"
"github.com/LazyBachelor/LazyPM/pkg/task"
ui "github.com/LazyBachelor/LazyPM/pkg/task/ui"
"github.com/charmbracelet/huh"
)
func NewCreateIssueTask() *Task {
func NewCreateIssueTask() *task.Task {
aboutScreen := ui.NewTaskModel(createIssueDetails())
questionnaire := ui.NewQuestionnaireModel(createIssueQuestionnaire())
task := NewTask(aboutScreen, questionnaire)
task := task.NewTask(aboutScreen, questionnaire)
task.SetConfigFunc(createIssueConfig)
task.SetDbStateFunc(createIssueDbState)
task.SetValidateFunc(createIssueValidate)
return task
}
func createIssueConfig() TaskConfig {
return TaskConfig{
func createIssueConfig() task.TaskConfig {
return task.TaskConfig{
IssuePrefix: "pm",
BeadsDBPath: "./.pm/db.db",
StatisticsStoragePath: "./.pm/task-1-stats.json",

View File

@@ -1,14 +0,0 @@
package ui
import (
"github.com/charmbracelet/huh"
"github.com/charmbracelet/lipgloss"
)
func theme() *huh.Theme {
theme := huh.ThemeBase16()
theme.Focused.Base = lipgloss.NewStyle().Align(lipgloss.Center)
return theme
}

View File

@@ -1,10 +1,9 @@
package tasks
package task
import (
"context"
"fmt"
"github.com/LazyBachelor/LazyPM/internal/service"
tea "github.com/charmbracelet/bubbletea"
)
@@ -16,7 +15,7 @@ func (t *Task) IntroduceTask() error {
return err
}
func (t *Task) StartInterface(ctx context.Context, cfg service.Config) error {
func (t *Task) StartInterface(ctx context.Context, cfg TaskConfig) error {
if t.interfaceType == nil {
return fmt.Errorf("interfaceType is not set")
}

View File

@@ -1,5 +1,4 @@
// task.go
package tasks
package task
import (
"context"

View File

@@ -1,4 +1,4 @@
package tasks
package task
import (
"context"

View File

@@ -1,4 +1,4 @@
package ui
package taskui
import "github.com/charmbracelet/bubbles/key"

View File

@@ -1,14 +1,15 @@
package ui
package taskui
import (
"charm.land/lipgloss/v2"
"github.com/LazyBachelor/LazyPM/internal/style"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/huh"
)
func NewQuestionnaireModel(questions Questions) *QuestionnaireModel {
form := huh.NewForm(questions...).
WithTheme(theme()).WithLayout(huh.LayoutGrid(1, 1))
WithTheme(style.HuhCenterTheme()).WithLayout(huh.LayoutGrid(1, 1))
return &QuestionnaireModel{
Questions: questions,

View File

@@ -1,4 +1,4 @@
package ui
package taskui
import (
"fmt"

View File

@@ -1,4 +1,4 @@
package ui
package taskui
import (
"github.com/charmbracelet/bubbles/help"