refactor to make cli better and simplify the code
This commit is contained in:
147
cmd/pm/init.go
Normal file
147
cmd/pm/init.go
Normal file
@@ -0,0 +1,147 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/cmd/pm/tasks"
|
||||
"github.com/LazyBachelor/LazyPM/internal/app"
|
||||
issues "github.com/LazyBachelor/LazyPM/internal/commands/issues"
|
||||
survey "github.com/LazyBachelor/LazyPM/internal/commands/survey"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/repl"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/task"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/tui"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/web"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
_ "github.com/LazyBachelor/LazyPM/cmd/pm/tasks"
|
||||
)
|
||||
|
||||
func init() {
|
||||
task.RegisterInterface("tui", tui.New())
|
||||
task.RegisterInterface("web", web.New())
|
||||
task.RegisterInterface("repl", repl.New())
|
||||
|
||||
task.RegisterTask("create_issue", func(app *app.App) task.Tasker {
|
||||
return tasks.NewCreateIssueTask(app)
|
||||
})
|
||||
task.RegisterTask("coding_task", func(app *app.App) task.Tasker {
|
||||
return tasks.NewCodingTask(app)
|
||||
})
|
||||
task.RegisterTask("git_task", func(app *app.App) task.Tasker {
|
||||
return tasks.NewGitTask(app)
|
||||
})
|
||||
task.RegisterTask("sprint_planning", func(app *app.App) task.Tasker {
|
||||
return tasks.NewSprintPlanningTask(app)
|
||||
})
|
||||
task.RegisterTask("issue_triage", func(app *app.App) task.Tasker {
|
||||
return tasks.NewIssueTriageTask(app)
|
||||
})
|
||||
task.RegisterTask("milestone_tracking", func(app *app.App) task.Tasker {
|
||||
return tasks.NewMilestoneTrackingTask(app)
|
||||
})
|
||||
task.RegisterTask("dependency_management", func(app *app.App) task.Tasker {
|
||||
return tasks.NewDependencyManagementTask(app)
|
||||
})
|
||||
task.RegisterTask("team_capacity", func(app *app.App) task.Tasker {
|
||||
return tasks.NewTeamCapacityTask(app)
|
||||
})
|
||||
task.RegisterTask("report_generation", func(app *app.App) task.Tasker {
|
||||
return tasks.NewReportGenerationTask(app)
|
||||
})
|
||||
task.RegisterTask("stakeholder_update", func(app *app.App) task.Tasker {
|
||||
return tasks.NewStakeholderUpdateTask(app)
|
||||
})
|
||||
task.RegisterTask("priority_management", func(app *app.App) task.Tasker {
|
||||
return tasks.NewPriorityManagementTask(app)
|
||||
})
|
||||
task.RegisterTask("backlog_refinement", func(app *app.App) task.Tasker {
|
||||
return tasks.NewBacklogRefinementTask(app)
|
||||
})
|
||||
|
||||
cobra.EnableCommandSorting = false
|
||||
|
||||
if os.Getenv("DEV") == "True" {
|
||||
issues.RootCmd.SetCompletionCommandGroupID("other")
|
||||
} else {
|
||||
issues.RootCmd.CompletionOptions.DisableDefaultCmd = true
|
||||
}
|
||||
|
||||
RootCmd.AddGroup(&cobra.Group{ID: "issues", Title: "Issue Management"})
|
||||
issues.CreateCmd.GroupID = "issues"
|
||||
issues.GetCmd.GroupID = "issues"
|
||||
issues.ListCmd.GroupID = "issues"
|
||||
issues.UpdateCmd.GroupID = "issues"
|
||||
issues.CloseCmd.GroupID = "issues"
|
||||
issues.DeleteCmd.GroupID = "issues"
|
||||
|
||||
RootCmd.AddCommand(issues.CreateCmd)
|
||||
RootCmd.AddCommand(issues.GetCmd)
|
||||
RootCmd.AddCommand(issues.ListCmd)
|
||||
RootCmd.AddCommand(issues.UpdateCmd)
|
||||
RootCmd.AddCommand(issues.CloseCmd)
|
||||
RootCmd.AddCommand(issues.DeleteCmd)
|
||||
|
||||
RootCmd.AddGroup(&cobra.Group{ID: "comment", Title: "Comment Management"})
|
||||
issues.CommentCmd.GroupID = "comment"
|
||||
issues.CommentsCmd.GroupID = "comment"
|
||||
RootCmd.AddCommand(issues.CommentCmd)
|
||||
RootCmd.AddCommand(issues.CommentsCmd)
|
||||
|
||||
var SurveyRootCmd = survey.RootCmd
|
||||
SurveyRootCmd.GroupID = "survey"
|
||||
RootCmd.AddGroup(&cobra.Group{ID: "survey", Title: "Survey Commands"})
|
||||
|
||||
survey.StartCmd.RunE = runStartCmd
|
||||
SurveyRootCmd.AddCommand(survey.StartCmd)
|
||||
SurveyRootCmd.AddCommand(survey.StatusCmd)
|
||||
SurveyRootCmd.AddCommand(survey.SubmitCmd)
|
||||
SurveyRootCmd.AddCommand(survey.ListTasksCmd)
|
||||
SurveyRootCmd.AddCommand(survey.ListInterfacesCmd)
|
||||
|
||||
RootCmd.AddCommand(SurveyRootCmd)
|
||||
|
||||
RootCmd.AddGroup(&cobra.Group{ID: "other", Title: "Additional Commands"})
|
||||
RootCmd.SetHelpCommandGroupID("other")
|
||||
RootCmd.AddCommand(replCmd)
|
||||
|
||||
}
|
||||
|
||||
var replCmd = &cobra.Command{
|
||||
Use: "repl",
|
||||
GroupID: "other",
|
||||
Short: "Start the interactive REPL interface",
|
||||
Long: `Start the interactive Read-Eval-Print Loop (REPL) for managing your projects and issues in an interactive terminal environment.`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return repl.New().Run(cmd.Context(), App.Config)
|
||||
},
|
||||
}
|
||||
|
||||
func initializeServices(ctx context.Context) (*app.App, func(), error) {
|
||||
return app.New(ctx, tasks.BaseConfig().WithAutoInit(true))
|
||||
}
|
||||
|
||||
func initInterfaces() map[string]task.Interface {
|
||||
interfaces := make(map[string]task.Interface)
|
||||
for _, name := range task.ListInterfaces() {
|
||||
i, err := task.GetInterface(name)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
interfaces[name] = i
|
||||
}
|
||||
return interfaces
|
||||
}
|
||||
|
||||
func initTasks(app *app.App) map[string]task.Tasker {
|
||||
taskMap := make(map[string]task.Tasker)
|
||||
for _, name := range task.ListTasks() {
|
||||
t, err := task.GetTask(name, app)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
taskMap[name] = t
|
||||
}
|
||||
|
||||
return taskMap
|
||||
}
|
||||
@@ -3,26 +3,29 @@ package main
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/internal/app"
|
||||
issues "github.com/LazyBachelor/LazyPM/internal/commands/issues"
|
||||
survey "github.com/LazyBachelor/LazyPM/internal/commands/survey"
|
||||
"github.com/LazyBachelor/LazyPM/internal/models"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/cli"
|
||||
"github.com/charmbracelet/fang"
|
||||
)
|
||||
|
||||
var App *app.App
|
||||
var RootCmd = issues.RootCmd
|
||||
|
||||
func main() {
|
||||
if err := cli.New(issues.RootCmd).Run(context.Background(), models.BaseConfig); err != nil {
|
||||
ctx := context.Background()
|
||||
app, cleanup, err := initializeServices(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer cleanup()
|
||||
|
||||
App = app
|
||||
survey.SetApp(App)
|
||||
issues.SetApp(App)
|
||||
|
||||
if err := fang.Execute(ctx, RootCmd,
|
||||
fang.WithColorSchemeFunc(fang.AnsiColorScheme)); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
issues.RootCmd.AddCommand(issues.GetCmd)
|
||||
issues.RootCmd.AddCommand(issues.ListCmd)
|
||||
issues.RootCmd.AddCommand(issues.CloseCmd)
|
||||
issues.RootCmd.AddCommand(issues.CreateCmd)
|
||||
issues.RootCmd.AddCommand(issues.DeleteCmd)
|
||||
issues.RootCmd.AddCommand(issues.UpdateCmd)
|
||||
issues.RootCmd.AddCommand(issues.CommentCmd)
|
||||
issues.RootCmd.AddCommand(issues.CommentsCmd)
|
||||
issues.RootCmd.AddCommand(survey.StatusCmd)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/cmd/survey/tasks"
|
||||
"github.com/LazyBachelor/LazyPM/cmd/pm/tasks"
|
||||
survey "github.com/LazyBachelor/LazyPM/internal/commands/survey"
|
||||
"github.com/LazyBachelor/LazyPM/internal/models"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/task"
|
||||
@@ -1,40 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/cmd/survey/tasks"
|
||||
"github.com/LazyBachelor/LazyPM/internal/app"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/task"
|
||||
|
||||
_ "github.com/LazyBachelor/LazyPM/cmd/survey/tasks"
|
||||
)
|
||||
|
||||
func initializeServices(ctx context.Context) (*app.App, func(), error) {
|
||||
return app.New(ctx, tasks.BaseConfig().WithAutoInit(true))
|
||||
}
|
||||
|
||||
func initInterfaces() map[string]task.Interface {
|
||||
interfaces := make(map[string]task.Interface)
|
||||
for _, name := range task.ListInterfaces() {
|
||||
i, err := task.GetInterface(name)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
interfaces[name] = i
|
||||
}
|
||||
return interfaces
|
||||
}
|
||||
|
||||
func initTasks(app *app.App) map[string]task.Tasker {
|
||||
taskMap := make(map[string]task.Tasker)
|
||||
for _, name := range task.ListTasks() {
|
||||
t, err := task.GetTask(name, app)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
taskMap[name] = t
|
||||
}
|
||||
|
||||
return taskMap
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/cmd/survey/tasks"
|
||||
"github.com/LazyBachelor/LazyPM/internal/app"
|
||||
issues "github.com/LazyBachelor/LazyPM/internal/commands/issues"
|
||||
survey "github.com/LazyBachelor/LazyPM/internal/commands/survey"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/repl"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/task"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/tui"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/web"
|
||||
"github.com/charmbracelet/fang"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
app, cleanup, err := initializeServices(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer cleanup()
|
||||
|
||||
survey.SetApp(app)
|
||||
issues.SetApp(app)
|
||||
|
||||
if err := fang.Execute(ctx, survey.RootCmd,
|
||||
fang.WithColorSchemeFunc(fang.AnsiColorScheme)); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
task.RegisterInterface("tui", tui.New())
|
||||
task.RegisterInterface("web", web.New())
|
||||
task.RegisterInterface("repl", repl.New())
|
||||
|
||||
task.RegisterTask("create_issue", func(app *app.App) task.Tasker {
|
||||
return tasks.NewCreateIssueTask(app)
|
||||
})
|
||||
task.RegisterTask("coding_task", func(app *app.App) task.Tasker {
|
||||
return tasks.NewCodingTask(app)
|
||||
})
|
||||
task.RegisterTask("git_task", func(app *app.App) task.Tasker {
|
||||
return tasks.NewGitTask(app)
|
||||
})
|
||||
task.RegisterTask("sprint_planning", func(app *app.App) task.Tasker {
|
||||
return tasks.NewSprintPlanningTask(app)
|
||||
})
|
||||
task.RegisterTask("issue_triage", func(app *app.App) task.Tasker {
|
||||
return tasks.NewIssueTriageTask(app)
|
||||
})
|
||||
task.RegisterTask("milestone_tracking", func(app *app.App) task.Tasker {
|
||||
return tasks.NewMilestoneTrackingTask(app)
|
||||
})
|
||||
task.RegisterTask("dependency_management", func(app *app.App) task.Tasker {
|
||||
return tasks.NewDependencyManagementTask(app)
|
||||
})
|
||||
task.RegisterTask("team_capacity", func(app *app.App) task.Tasker {
|
||||
return tasks.NewTeamCapacityTask(app)
|
||||
})
|
||||
task.RegisterTask("report_generation", func(app *app.App) task.Tasker {
|
||||
return tasks.NewReportGenerationTask(app)
|
||||
})
|
||||
task.RegisterTask("stakeholder_update", func(app *app.App) task.Tasker {
|
||||
return tasks.NewStakeholderUpdateTask(app)
|
||||
})
|
||||
task.RegisterTask("priority_management", func(app *app.App) task.Tasker {
|
||||
return tasks.NewPriorityManagementTask(app)
|
||||
})
|
||||
task.RegisterTask("backlog_refinement", func(app *app.App) task.Tasker {
|
||||
return tasks.NewBacklogRefinementTask(app)
|
||||
})
|
||||
|
||||
// Basic survey commands
|
||||
survey.StartCmd.RunE = runStartCmd
|
||||
survey.RootCmd.AddCommand(survey.StartCmd)
|
||||
survey.RootCmd.AddCommand(survey.SubmitCmd)
|
||||
survey.RootCmd.AddCommand(survey.StatusCmd)
|
||||
survey.RootCmd.AddCommand(survey.ListTasksCmd)
|
||||
survey.RootCmd.AddCommand(survey.ListInterfacesCmd)
|
||||
survey.RootCmd.AddCommand(survey.IssuesCmd)
|
||||
|
||||
// Issue related commands
|
||||
survey.IssuesCmd.AddCommand(issues.ListCmd)
|
||||
survey.IssuesCmd.AddCommand(issues.CreateCmd)
|
||||
survey.IssuesCmd.AddCommand(issues.UpdateCmd)
|
||||
survey.IssuesCmd.AddCommand(issues.DeleteCmd)
|
||||
survey.IssuesCmd.AddCommand(issues.CloseCmd)
|
||||
survey.IssuesCmd.AddCommand(issues.CommentCmd)
|
||||
survey.IssuesCmd.AddCommand(issues.CommentsCmd)
|
||||
|
||||
// Issue commands for the REPL interface
|
||||
issues.RootCmd.AddCommand(issues.GetCmd)
|
||||
issues.RootCmd.AddCommand(issues.ListCmd)
|
||||
issues.RootCmd.AddCommand(issues.CloseCmd)
|
||||
issues.RootCmd.AddCommand(issues.CreateCmd)
|
||||
issues.RootCmd.AddCommand(issues.DeleteCmd)
|
||||
issues.RootCmd.AddCommand(issues.UpdateCmd)
|
||||
issues.RootCmd.AddCommand(issues.CommentCmd)
|
||||
issues.RootCmd.AddCommand(issues.CommentsCmd)
|
||||
issues.RootCmd.AddCommand(survey.StatusCmd)
|
||||
}
|
||||
Reference in New Issue
Block a user