From e994c890f460f7b5f53a276ae3af968507c9c9b2 Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Fri, 13 Feb 2026 10:13:41 +0100 Subject: [PATCH] refactor survery cmd move package files to pkg --- cmd/survey/init.go | 9 +++++---- cmd/survey/survey.go | 6 ++---- cmd/survey/tasks/createIssue.go | 11 ++++++----- cmd/survey/ui/style.go | 14 -------------- {cmd/survey/tasks => pkg/task}/runner.go | 5 ++--- {cmd/survey/tasks => pkg/task}/task.go | 3 +-- {cmd/survey/tasks => pkg/task}/types.go | 2 +- {cmd/survey => pkg/task}/ui/help.go | 2 +- {cmd/survey => pkg/task}/ui/questionnaire.go | 5 +++-- {cmd/survey => pkg/task}/ui/task.go | 2 +- {cmd/survey => pkg/task}/ui/types.go | 2 +- 11 files changed, 23 insertions(+), 38 deletions(-) delete mode 100644 cmd/survey/ui/style.go rename {cmd/survey/tasks => pkg/task}/runner.go (80%) rename {cmd/survey/tasks => pkg/task}/task.go (97%) rename {cmd/survey/tasks => pkg/task}/types.go (96%) rename {cmd/survey => pkg/task}/ui/help.go (97%) rename {cmd/survey => pkg/task}/ui/questionnaire.go (88%) rename {cmd/survey => pkg/task}/ui/task.go (99%) rename {cmd/survey => pkg/task}/ui/types.go (96%) diff --git a/cmd/survey/init.go b/cmd/survey/init.go index 84f7609..772af6f 100644 --- a/cmd/survey/init.go +++ b/cmd/survey/init.go @@ -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()} } diff --git a/cmd/survey/survey.go b/cmd/survey/survey.go index a270790..64e36e2 100644 --- a/cmd/survey/survey.go +++ b/cmd/survey/survey.go @@ -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 { diff --git a/cmd/survey/tasks/createIssue.go b/cmd/survey/tasks/createIssue.go index 9f0d11d..9a9a2d4 100644 --- a/cmd/survey/tasks/createIssue.go +++ b/cmd/survey/tasks/createIssue.go @@ -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", diff --git a/cmd/survey/ui/style.go b/cmd/survey/ui/style.go deleted file mode 100644 index 9a2b4f4..0000000 --- a/cmd/survey/ui/style.go +++ /dev/null @@ -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 -} diff --git a/cmd/survey/tasks/runner.go b/pkg/task/runner.go similarity index 80% rename from cmd/survey/tasks/runner.go rename to pkg/task/runner.go index 2e8c89f..9ad8b0a 100644 --- a/cmd/survey/tasks/runner.go +++ b/pkg/task/runner.go @@ -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") } diff --git a/cmd/survey/tasks/task.go b/pkg/task/task.go similarity index 97% rename from cmd/survey/tasks/task.go rename to pkg/task/task.go index 9e6553b..2a9e548 100644 --- a/cmd/survey/tasks/task.go +++ b/pkg/task/task.go @@ -1,5 +1,4 @@ -// task.go -package tasks +package task import ( "context" diff --git a/cmd/survey/tasks/types.go b/pkg/task/types.go similarity index 96% rename from cmd/survey/tasks/types.go rename to pkg/task/types.go index 74af23c..90427d5 100644 --- a/cmd/survey/tasks/types.go +++ b/pkg/task/types.go @@ -1,4 +1,4 @@ -package tasks +package task import ( "context" diff --git a/cmd/survey/ui/help.go b/pkg/task/ui/help.go similarity index 97% rename from cmd/survey/ui/help.go rename to pkg/task/ui/help.go index 15b58a6..ebc31e4 100644 --- a/cmd/survey/ui/help.go +++ b/pkg/task/ui/help.go @@ -1,4 +1,4 @@ -package ui +package taskui import "github.com/charmbracelet/bubbles/key" diff --git a/cmd/survey/ui/questionnaire.go b/pkg/task/ui/questionnaire.go similarity index 88% rename from cmd/survey/ui/questionnaire.go rename to pkg/task/ui/questionnaire.go index 9849a60..e7dc01d 100644 --- a/cmd/survey/ui/questionnaire.go +++ b/pkg/task/ui/questionnaire.go @@ -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, diff --git a/cmd/survey/ui/task.go b/pkg/task/ui/task.go similarity index 99% rename from cmd/survey/ui/task.go rename to pkg/task/ui/task.go index 5e5314e..81da4e6 100644 --- a/cmd/survey/ui/task.go +++ b/pkg/task/ui/task.go @@ -1,4 +1,4 @@ -package ui +package taskui import ( "fmt" diff --git a/cmd/survey/ui/types.go b/pkg/task/ui/types.go similarity index 96% rename from cmd/survey/ui/types.go rename to pkg/task/ui/types.go index ec382be..dc6a47e 100644 --- a/cmd/survey/ui/types.go +++ b/pkg/task/ui/types.go @@ -1,4 +1,4 @@ -package ui +package taskui import ( "github.com/charmbracelet/bubbles/help"