refactor names and minimize dependencies
This commit is contained in:
@@ -18,7 +18,7 @@ type CLI struct {
|
||||
RootCmd *cobra.Command
|
||||
}
|
||||
|
||||
func NewCli(rootCmd *cobra.Command) *CLI {
|
||||
func New(rootCmd *cobra.Command) *CLI {
|
||||
return &CLI{
|
||||
RootCmd: rootCmd,
|
||||
}
|
||||
|
||||
@@ -30,15 +30,15 @@ You can also run shell commands directly. Type 'exit' or 'quit' to leave.`
|
||||
)
|
||||
|
||||
type REPL struct {
|
||||
feedbackChan chan task.ValidationFeedback
|
||||
feedbackChan chan ValidationFeedback
|
||||
quitChan chan bool
|
||||
app *App
|
||||
|
||||
currentFeedback task.ValidationFeedback
|
||||
currentFeedback ValidationFeedback
|
||||
exitRequested bool
|
||||
}
|
||||
|
||||
func NewRepl() *REPL {
|
||||
func New() *REPL {
|
||||
return &REPL{}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package taskui
|
||||
package task
|
||||
|
||||
import (
|
||||
"charm.land/lipgloss/v2"
|
||||
@@ -2,8 +2,6 @@ package task
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
||||
)
|
||||
|
||||
var interfaceRegistry = make(map[string]Interface)
|
||||
@@ -31,16 +29,16 @@ func ListInterfaces() []string {
|
||||
return names
|
||||
}
|
||||
|
||||
var taskRegistry = make(map[string]func(*service.App) Tasker)
|
||||
var taskRegistry = make(map[string]func(*App) Tasker)
|
||||
|
||||
func RegisterTask(name string, constructor func(*service.App) Tasker) {
|
||||
func RegisterTask(name string, constructor func(*App) Tasker) {
|
||||
if _, exists := taskRegistry[name]; exists {
|
||||
panic(fmt.Sprintf("task %q already registered", name))
|
||||
}
|
||||
taskRegistry[name] = constructor
|
||||
}
|
||||
|
||||
func GetTask(name string, app *service.App) (Tasker, error) {
|
||||
func GetTask(name string, app *App) (Tasker, error) {
|
||||
constructor, ok := taskRegistry[name]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("task %q not found", name)
|
||||
|
||||
@@ -6,10 +6,10 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/internal/models"
|
||||
taskui "github.com/LazyBachelor/LazyPM/pkg/task/ui"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
type App = models.App
|
||||
type Config = models.Config
|
||||
|
||||
type Tasker = models.Tasker
|
||||
@@ -43,7 +43,7 @@ func RunTask(ctx context.Context, t Tasker, i Interface, iType InterfaceType) er
|
||||
}
|
||||
|
||||
// Show task intro
|
||||
detailsScreen := taskui.NewTaskModel(t.Details())
|
||||
detailsScreen := NewTaskModel(t.Details())
|
||||
model, err := tea.NewProgram(detailsScreen, tea.WithAltScreen()).Run()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -79,7 +79,7 @@ func RunTask(ctx context.Context, t Tasker, i Interface, iType InterfaceType) er
|
||||
|
||||
// Show questionnaire
|
||||
questions := t.Questions(iType)
|
||||
questionare := taskui.NewQuestionnaireModel(questions)
|
||||
questionare := NewQuestionnaireModel(questions)
|
||||
model, err = tea.NewProgram(questionare, tea.WithAltScreen()).Run()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package taskui
|
||||
package task
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -17,7 +17,7 @@ type Tui struct {
|
||||
quitChan chan bool
|
||||
}
|
||||
|
||||
func NewTui() *Tui {
|
||||
func New() *Tui {
|
||||
return &Tui{}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ type Web struct {
|
||||
quitChan chan bool
|
||||
}
|
||||
|
||||
func NewWeb() *Web {
|
||||
func New() *Web {
|
||||
return &Web{}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user