refactor survery cmd
move package files to pkg
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/LazyBachelor/LazyPM/cmd/survey/tasks"
|
"github.com/LazyBachelor/LazyPM/cmd/survey/tasks"
|
||||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
"github.com/LazyBachelor/LazyPM/internal/service"
|
||||||
"github.com/LazyBachelor/LazyPM/pkg/cli/repl"
|
"github.com/LazyBachelor/LazyPM/pkg/cli/repl"
|
||||||
|
"github.com/LazyBachelor/LazyPM/pkg/task"
|
||||||
"github.com/LazyBachelor/LazyPM/pkg/tui"
|
"github.com/LazyBachelor/LazyPM/pkg/tui"
|
||||||
"github.com/LazyBachelor/LazyPM/pkg/web"
|
"github.com/LazyBachelor/LazyPM/pkg/web"
|
||||||
)
|
)
|
||||||
@@ -20,13 +21,13 @@ func initializeServices(ctx context.Context) (*service.Services, func(), error)
|
|||||||
return service.NewServices(ctx, config)
|
return service.NewServices(ctx, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
func initTasks() []*tasks.Task {
|
func initTasks() []*task.Task {
|
||||||
return []*tasks.Task{
|
return []*task.Task{
|
||||||
tasks.NewCreateIssueTask(),
|
tasks.NewCreateIssueTask(),
|
||||||
tasks.NewCreateIssueTask(),
|
tasks.NewCreateIssueTask(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func initInterfaces() []tasks.Interface {
|
func initInterfaces() []task.Interface {
|
||||||
return []tasks.Interface{repl.NewRepl(), tui.NewTui(), web.NewWeb()}
|
return []task.Interface{repl.NewRepl(), tui.NewTui(), web.NewWeb()}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,14 +5,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/LazyBachelor/LazyPM/cmd/survey/tasks"
|
|
||||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
"github.com/LazyBachelor/LazyPM/internal/service"
|
||||||
|
"github.com/LazyBachelor/LazyPM/pkg/task"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
rand.Seed(time.Now().UnixNano())
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
svc, close, err := initializeServices(ctx)
|
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)
|
interfaceIndex := rand.Int() % len(interfaces)
|
||||||
|
|
||||||
for _, task := range surveyTasks {
|
for _, task := range surveyTasks {
|
||||||
|
|||||||
@@ -4,25 +4,26 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/LazyBachelor/LazyPM/cmd/survey/ui"
|
|
||||||
"github.com/LazyBachelor/LazyPM/internal/models"
|
"github.com/LazyBachelor/LazyPM/internal/models"
|
||||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
"github.com/LazyBachelor/LazyPM/internal/service"
|
||||||
|
"github.com/LazyBachelor/LazyPM/pkg/task"
|
||||||
|
ui "github.com/LazyBachelor/LazyPM/pkg/task/ui"
|
||||||
"github.com/charmbracelet/huh"
|
"github.com/charmbracelet/huh"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewCreateIssueTask() *Task {
|
func NewCreateIssueTask() *task.Task {
|
||||||
aboutScreen := ui.NewTaskModel(createIssueDetails())
|
aboutScreen := ui.NewTaskModel(createIssueDetails())
|
||||||
questionnaire := ui.NewQuestionnaireModel(createIssueQuestionnaire())
|
questionnaire := ui.NewQuestionnaireModel(createIssueQuestionnaire())
|
||||||
|
|
||||||
task := NewTask(aboutScreen, questionnaire)
|
task := task.NewTask(aboutScreen, questionnaire)
|
||||||
task.SetConfigFunc(createIssueConfig)
|
task.SetConfigFunc(createIssueConfig)
|
||||||
task.SetDbStateFunc(createIssueDbState)
|
task.SetDbStateFunc(createIssueDbState)
|
||||||
task.SetValidateFunc(createIssueValidate)
|
task.SetValidateFunc(createIssueValidate)
|
||||||
return task
|
return task
|
||||||
}
|
}
|
||||||
|
|
||||||
func createIssueConfig() TaskConfig {
|
func createIssueConfig() task.TaskConfig {
|
||||||
return TaskConfig{
|
return task.TaskConfig{
|
||||||
IssuePrefix: "pm",
|
IssuePrefix: "pm",
|
||||||
BeadsDBPath: "./.pm/db.db",
|
BeadsDBPath: "./.pm/db.db",
|
||||||
StatisticsStoragePath: "./.pm/task-1-stats.json",
|
StatisticsStoragePath: "./.pm/task-1-stats.json",
|
||||||
|
|||||||
@@ -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
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
package tasks
|
package task
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,7 +15,7 @@ func (t *Task) IntroduceTask() error {
|
|||||||
return err
|
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 {
|
if t.interfaceType == nil {
|
||||||
return fmt.Errorf("interfaceType is not set")
|
return fmt.Errorf("interfaceType is not set")
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
// task.go
|
package task
|
||||||
package tasks
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package tasks
|
package task
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package ui
|
package taskui
|
||||||
|
|
||||||
import "github.com/charmbracelet/bubbles/key"
|
import "github.com/charmbracelet/bubbles/key"
|
||||||
|
|
||||||
@@ -1,14 +1,15 @@
|
|||||||
package ui
|
package taskui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"charm.land/lipgloss/v2"
|
"charm.land/lipgloss/v2"
|
||||||
|
"github.com/LazyBachelor/LazyPM/internal/style"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/huh"
|
"github.com/charmbracelet/huh"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewQuestionnaireModel(questions Questions) *QuestionnaireModel {
|
func NewQuestionnaireModel(questions Questions) *QuestionnaireModel {
|
||||||
form := huh.NewForm(questions...).
|
form := huh.NewForm(questions...).
|
||||||
WithTheme(theme()).WithLayout(huh.LayoutGrid(1, 1))
|
WithTheme(style.HuhCenterTheme()).WithLayout(huh.LayoutGrid(1, 1))
|
||||||
|
|
||||||
return &QuestionnaireModel{
|
return &QuestionnaireModel{
|
||||||
Questions: questions,
|
Questions: questions,
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package ui
|
package taskui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package ui
|
package taskui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/charmbracelet/bubbles/help"
|
"github.com/charmbracelet/bubbles/help"
|
||||||
Reference in New Issue
Block a user