From 9612cb9338d0dbeb5131e26e4663417263f7e3f0 Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Sun, 1 Mar 2026 20:42:56 +0100 Subject: [PATCH 1/3] refactor to make cli better and simplify the code --- .goreleaser.yaml | 2 +- Dockerfile | 2 +- Makefile | 19 +-- cmd/pm/init.go | 147 ++++++++++++++++++ cmd/{survey => pm}/intro.go | 0 cmd/pm/main.go | 33 ++-- cmd/{survey => pm}/runner.go | 2 +- cmd/{survey => pm}/tasks/backlogRefinement.go | 0 cmd/{survey => pm}/tasks/base.go | 0 cmd/{survey => pm}/tasks/codingTask.go | 0 cmd/{survey => pm}/tasks/createIssue.go | 0 .../tasks/dependencyManagement.go | 0 cmd/{survey => pm}/tasks/gitTask.go | 0 cmd/{survey => pm}/tasks/issueTriage.go | 0 cmd/{survey => pm}/tasks/milestoneTracking.go | 0 .../tasks/priorityManagement.go | 0 cmd/{survey => pm}/tasks/reportGeneration.go | 0 cmd/{survey => pm}/tasks/sprintPlanning.go | 0 cmd/{survey => pm}/tasks/stakeholderUpdate.go | 0 cmd/{survey => pm}/tasks/teamCapacity.go | 0 cmd/survey/init.go | 40 ----- cmd/survey/main.go | 104 ------------- internal/commands/issues/close.go | 1 + internal/commands/issues/comment.go | 2 +- internal/commands/issues/comments_list.go | 2 +- internal/commands/issues/create.go | 2 +- internal/commands/issues/list.go | 2 +- internal/commands/issues/read.go | 4 +- internal/commands/issues/root.go | 8 - internal/commands/issues/update.go | 2 +- pkg/cli/cli.go | 62 -------- pkg/repl/repl.go | 3 +- 32 files changed, 182 insertions(+), 255 deletions(-) create mode 100644 cmd/pm/init.go rename cmd/{survey => pm}/intro.go (100%) rename cmd/{survey => pm}/runner.go (97%) rename cmd/{survey => pm}/tasks/backlogRefinement.go (100%) rename cmd/{survey => pm}/tasks/base.go (100%) rename cmd/{survey => pm}/tasks/codingTask.go (100%) rename cmd/{survey => pm}/tasks/createIssue.go (100%) rename cmd/{survey => pm}/tasks/dependencyManagement.go (100%) rename cmd/{survey => pm}/tasks/gitTask.go (100%) rename cmd/{survey => pm}/tasks/issueTriage.go (100%) rename cmd/{survey => pm}/tasks/milestoneTracking.go (100%) rename cmd/{survey => pm}/tasks/priorityManagement.go (100%) rename cmd/{survey => pm}/tasks/reportGeneration.go (100%) rename cmd/{survey => pm}/tasks/sprintPlanning.go (100%) rename cmd/{survey => pm}/tasks/stakeholderUpdate.go (100%) rename cmd/{survey => pm}/tasks/teamCapacity.go (100%) delete mode 100644 cmd/survey/init.go delete mode 100644 cmd/survey/main.go delete mode 100644 pkg/cli/cli.go diff --git a/.goreleaser.yaml b/.goreleaser.yaml index db691e2..1fa4ee1 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -16,7 +16,7 @@ before: - go generate ./... builds: - - main: ./cmd/survey + - main: ./cmd/pm env: - CGO_ENABLED=0 goos: diff --git a/Dockerfile b/Dockerfile index cf7e6e6..7a732b4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,7 +15,7 @@ RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build \ -a -installsuffix cgo \ -ldflags="-w -s" \ -trimpath \ - -o pm ./cmd/survey/ + -o pm ./cmd/pm/ FROM gcr.io/distroless/static-debian13 WORKDIR /data diff --git a/Makefile b/Makefile index 3de9931..a864b41 100644 --- a/Makefile +++ b/Makefile @@ -13,15 +13,12 @@ clean: @rm -f package-lock.json @rm -f package.json @rm -f ./build/pm - @rm -f ./build/survey - @rm -f ./build/survey_bash.sh @rm -f ./build/pm_bash.sh build: tidy @go build -o ./bin/pm ./cmd/pm @go build -o ./bin/tui ./cmd/tui @go build -o ./bin/web ./cmd/web - @go build -o ./bin/survey ./cmd/survey @echo "Build completed successfully. Binaries are located in the ./bin directory." enable-multiplatform-build: @@ -41,8 +38,6 @@ docker-push: os-build: build completions @cp ./bin/pm ./build/pm - @cp ./bin/survey ./build/survey - @cp ./bin/survey_bash.sh ./build/survey_bash.sh @cp ./bin/pm_bash.sh ./build/pm_bash.sh @docker build -t telikz/lazyos ./build @echo "Built lazyos image successfully. You can run it using 'make os-run'." @@ -60,7 +55,7 @@ os-push: @docker push telikz/lazyos start: - @go run ./cmd/survey start + @go run ./cmd/pm survey start cli: tidy go run ./cmd/pm @@ -85,12 +80,10 @@ tw: tw-install completions: @mkdir -p ./bin @go build -o ./bin/pm ./cmd/pm - @go build -o ./bin/survey ./cmd/survey - @./bin/survey completion bash > ./bin/survey_bash.sh - @./bin/pm completion bash > ./bin/pm_bash.sh - @./bin/pm completion zsh > ./bin/pm_zsh.sh - @./bin/pm completion fish > ./bin/pm_fish.sh - @./bin/pm completion powershell > ./bin/pm_powershell.ps1 + @DEV=True ./bin/pm completion bash > ./bin/pm_bash.sh + @DEV=True ./bin/pm completion zsh > ./bin/pm_zsh.sh + @DEV=True ./bin/pm completion fish > ./bin/pm_fish.sh + @DEV=True ./bin/pm completion powershell > ./bin/pm_powershell.ps1 install-bash-temp: completions @go install ./cmd/pm @@ -111,9 +104,7 @@ install-powershell-temp: completions install-cli: completions @go install ./cmd/pm - @go install ./cmd/survey @sudo cp ./bin/pm_bash.sh /etc/bash_completion.d/pm - @sudo cp ./bin/survey_bash.sh /etc/bash_completion.d/survey .PHONY: tidy clean build docker-build docker-run docker-push os-build os-run os-stop os-push start cli tui web tw-install dev tw completions install-bash-temp install-zsh-temp install-fish-temp install-powershell-temp install-cli diff --git a/cmd/pm/init.go b/cmd/pm/init.go new file mode 100644 index 0000000..974ea21 --- /dev/null +++ b/cmd/pm/init.go @@ -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 +} diff --git a/cmd/survey/intro.go b/cmd/pm/intro.go similarity index 100% rename from cmd/survey/intro.go rename to cmd/pm/intro.go diff --git a/cmd/pm/main.go b/cmd/pm/main.go index 706cd5b..77519f4 100644 --- a/cmd/pm/main.go +++ b/cmd/pm/main.go @@ -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) -} diff --git a/cmd/survey/runner.go b/cmd/pm/runner.go similarity index 97% rename from cmd/survey/runner.go rename to cmd/pm/runner.go index 1c3a78c..53ba5b5 100644 --- a/cmd/survey/runner.go +++ b/cmd/pm/runner.go @@ -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" diff --git a/cmd/survey/tasks/backlogRefinement.go b/cmd/pm/tasks/backlogRefinement.go similarity index 100% rename from cmd/survey/tasks/backlogRefinement.go rename to cmd/pm/tasks/backlogRefinement.go diff --git a/cmd/survey/tasks/base.go b/cmd/pm/tasks/base.go similarity index 100% rename from cmd/survey/tasks/base.go rename to cmd/pm/tasks/base.go diff --git a/cmd/survey/tasks/codingTask.go b/cmd/pm/tasks/codingTask.go similarity index 100% rename from cmd/survey/tasks/codingTask.go rename to cmd/pm/tasks/codingTask.go diff --git a/cmd/survey/tasks/createIssue.go b/cmd/pm/tasks/createIssue.go similarity index 100% rename from cmd/survey/tasks/createIssue.go rename to cmd/pm/tasks/createIssue.go diff --git a/cmd/survey/tasks/dependencyManagement.go b/cmd/pm/tasks/dependencyManagement.go similarity index 100% rename from cmd/survey/tasks/dependencyManagement.go rename to cmd/pm/tasks/dependencyManagement.go diff --git a/cmd/survey/tasks/gitTask.go b/cmd/pm/tasks/gitTask.go similarity index 100% rename from cmd/survey/tasks/gitTask.go rename to cmd/pm/tasks/gitTask.go diff --git a/cmd/survey/tasks/issueTriage.go b/cmd/pm/tasks/issueTriage.go similarity index 100% rename from cmd/survey/tasks/issueTriage.go rename to cmd/pm/tasks/issueTriage.go diff --git a/cmd/survey/tasks/milestoneTracking.go b/cmd/pm/tasks/milestoneTracking.go similarity index 100% rename from cmd/survey/tasks/milestoneTracking.go rename to cmd/pm/tasks/milestoneTracking.go diff --git a/cmd/survey/tasks/priorityManagement.go b/cmd/pm/tasks/priorityManagement.go similarity index 100% rename from cmd/survey/tasks/priorityManagement.go rename to cmd/pm/tasks/priorityManagement.go diff --git a/cmd/survey/tasks/reportGeneration.go b/cmd/pm/tasks/reportGeneration.go similarity index 100% rename from cmd/survey/tasks/reportGeneration.go rename to cmd/pm/tasks/reportGeneration.go diff --git a/cmd/survey/tasks/sprintPlanning.go b/cmd/pm/tasks/sprintPlanning.go similarity index 100% rename from cmd/survey/tasks/sprintPlanning.go rename to cmd/pm/tasks/sprintPlanning.go diff --git a/cmd/survey/tasks/stakeholderUpdate.go b/cmd/pm/tasks/stakeholderUpdate.go similarity index 100% rename from cmd/survey/tasks/stakeholderUpdate.go rename to cmd/pm/tasks/stakeholderUpdate.go diff --git a/cmd/survey/tasks/teamCapacity.go b/cmd/pm/tasks/teamCapacity.go similarity index 100% rename from cmd/survey/tasks/teamCapacity.go rename to cmd/pm/tasks/teamCapacity.go diff --git a/cmd/survey/init.go b/cmd/survey/init.go deleted file mode 100644 index e140edc..0000000 --- a/cmd/survey/init.go +++ /dev/null @@ -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 -} diff --git a/cmd/survey/main.go b/cmd/survey/main.go deleted file mode 100644 index 4916a46..0000000 --- a/cmd/survey/main.go +++ /dev/null @@ -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) -} diff --git a/internal/commands/issues/close.go b/internal/commands/issues/close.go index 3c89b10..0665fe8 100644 --- a/internal/commands/issues/close.go +++ b/internal/commands/issues/close.go @@ -14,6 +14,7 @@ var CloseCmd = &cobra.Command{ Short: "Close an existing issue", Long: `Close an existing issue by its ID.`, Example: `pm close pm-abc`, + Args: cobra.ExactArgs(1), RunE: runCloseCmd, diff --git a/internal/commands/issues/comment.go b/internal/commands/issues/comment.go index 0cdbdc5..c1d9f11 100644 --- a/internal/commands/issues/comment.go +++ b/internal/commands/issues/comment.go @@ -20,7 +20,7 @@ pm comment ISSUE-1 LGTM --author alice pm comment ISSUE-1 -m "Needs review"` var CommentCmd = &cobra.Command{ - Use: "comment [issue ID] [message...]", + Use: "comment [id] [message...]", Short: "Add a comment on an issue", Long: `Add a comment on an issue by ID. All arguments after the issue ID form the message (no quotes needed), or use --message.`, Example: commentCmdExample, diff --git a/internal/commands/issues/comments_list.go b/internal/commands/issues/comments_list.go index 762efef..7d85cff 100644 --- a/internal/commands/issues/comments_list.go +++ b/internal/commands/issues/comments_list.go @@ -8,7 +8,7 @@ import ( // CommentsCmd represents the command to list comments on an issue. var CommentsCmd = &cobra.Command{ - Use: "comments [issue ID]", + Use: "comments [id]", Short: "List comments on an issue", Long: `List all comments on an issue by ID.`, diff --git a/internal/commands/issues/create.go b/internal/commands/issues/create.go index c69aa68..8e1eb7e 100644 --- a/internal/commands/issues/create.go +++ b/internal/commands/issues/create.go @@ -21,7 +21,7 @@ pm create Fix bug --desc "Bug description" --status in_progress --type bug --pri // CreateCmd represents the create command, which allows users to create a new issue with specified details. var CreateCmd = &cobra.Command{ - Use: "create [title]", + Use: "create [title...]", Short: "Create a new issue", Long: `Create a new issue with the specified details.`, Example: createCmdExample, diff --git a/internal/commands/issues/list.go b/internal/commands/issues/list.go index bd0bd63..8b8c451 100644 --- a/internal/commands/issues/list.go +++ b/internal/commands/issues/list.go @@ -20,7 +20,7 @@ pm list -p 1 -l 10` // ListCmd represents the get issues command. var ListCmd = &cobra.Command{ - Use: "list [search query]", + Use: "list [query]", Short: "List all issues", Long: `List all issues in the project management system.`, Example: lsExamples, diff --git a/internal/commands/issues/read.go b/internal/commands/issues/read.go index 81cd4f4..082d849 100644 --- a/internal/commands/issues/read.go +++ b/internal/commands/issues/read.go @@ -7,13 +7,13 @@ import ( // GetCmd represents the get issue command. var GetCmd = &cobra.Command{ - Use: "describe [issue ID]", + Use: "read [id]", Short: "Get issue details", Long: `Get issue details by ID`, ValidArgsFunction: completeIssues, - Aliases: []string{"get", "read"}, + Aliases: []string{"get", "describe", "details"}, Args: cobra.ExactArgs(1), RunE: runGetCmd, } diff --git a/internal/commands/issues/root.go b/internal/commands/issues/root.go index 25ad934..22e242f 100644 --- a/internal/commands/issues/root.go +++ b/internal/commands/issues/root.go @@ -85,11 +85,3 @@ func ExecuteArgsStringWithContext(ctx context.Context, args []string) (string, e return buf.String(), err } - -// init function to set up the command hierarchy and options. -func init() { - RootCmd.CompletionOptions.DisableDefaultCmd = false - RootCmd.AddGroup(&cobra.Group{ID: "help", Title: "Helping Commands"}) - RootCmd.SetCompletionCommandGroupID("help") - RootCmd.SetHelpCommandGroupID("help") -} diff --git a/internal/commands/issues/update.go b/internal/commands/issues/update.go index 24e570f..eaaceb4 100644 --- a/internal/commands/issues/update.go +++ b/internal/commands/issues/update.go @@ -11,7 +11,7 @@ import ( var updateFlags Flags var UpdateCmd = &cobra.Command{ - Use: "update [issue ID]", + Use: "update [id]", Short: "Update an existing issue", Long: `Update an existing issue by its ID with the specified details.`, Example: `pm update pm-001 --title "New title" -d "Description" -s in_progress --type task -p 3`, diff --git a/pkg/cli/cli.go b/pkg/cli/cli.go deleted file mode 100644 index 1ecfb79..0000000 --- a/pkg/cli/cli.go +++ /dev/null @@ -1,62 +0,0 @@ -// Package cli provides the command-line interface for the PM System. -package cli - -import ( - "context" - - "github.com/LazyBachelor/LazyPM/internal/app" - issues "github.com/LazyBachelor/LazyPM/internal/commands/issues" - "github.com/LazyBachelor/LazyPM/internal/models" - "github.com/charmbracelet/fang" - "github.com/spf13/cobra" -) - -// Config is an alias for app.Config, used to configure the CLI. -type Config = models.Config - -type CLI struct { - RootCmd *cobra.Command -} - -func New(rootCmd *cobra.Command) *CLI { - return &CLI{ - RootCmd: rootCmd, - } -} - -// Run initializes the services and executes the CLI commands. -func (c *CLI) Run(ctx context.Context, config Config) error { - app, cleanup, err := app.New(ctx, config) - if err != nil { - return err - } - - defer cleanup() - - issues.SetApp(app) - - if err := fang.Execute(ctx, c.RootCmd, - fang.WithColorSchemeFunc(fang.AnsiColorScheme)); err != nil { - return err - } - - return nil -} - -// RunWithArgs initializes the services and executes the CLI commands with the provided arguments. -func (c *CLI) RunWithArgs(ctx context.Context, config Config, args []string) error { - app, cleanup, err := app.New(ctx, config) - if err != nil { - return err - } - - defer cleanup() - - issues.SetApp(app) - - if err := issues.ExecuteArgs(args); err != nil { - return err - } - - return nil -} diff --git a/pkg/repl/repl.go b/pkg/repl/repl.go index ce3c52b..0c999f0 100644 --- a/pkg/repl/repl.go +++ b/pkg/repl/repl.go @@ -11,7 +11,6 @@ import ( issues "github.com/LazyBachelor/LazyPM/internal/commands/issues" "github.com/LazyBachelor/LazyPM/internal/models" "github.com/LazyBachelor/LazyPM/internal/style" - "github.com/LazyBachelor/LazyPM/pkg/cli" "github.com/LazyBachelor/LazyPM/pkg/task" "github.com/LazyBachelor/LazyPM/pkg/tui/styles" "github.com/c-bata/go-prompt" @@ -43,7 +42,7 @@ func New() *REPL { } // Run starts the interactive Read-Eval-Print Loop for the PM CLI. -func (r *REPL) Run(ctx context.Context, config cli.Config) error { +func (r *REPL) Run(ctx context.Context, config app.Config) error { // Set terminal to raw mode to capture input properly in the REPL. // This allows us to handle input character by character and provide a better user experience. // We also ensure that the terminal state is restored when the REPL exits, even if an error occurs. From 447f97ec3e7a071d32a6d854a4afba9f1ef4a139 Mon Sep 17 00:00:00 2001 From: Robin Olsen <129996395+Telikz@users.noreply.github.com> Date: Sun, 1 Mar 2026 20:54:17 +0100 Subject: [PATCH 2/3] Update cmd/pm/init.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- cmd/pm/init.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/cmd/pm/init.go b/cmd/pm/init.go index 974ea21..22bd4c3 100644 --- a/cmd/pm/init.go +++ b/cmd/pm/init.go @@ -13,8 +13,6 @@ import ( "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() { From 37862c7bae4ea60c6bcbbea8dbc2d8f254ddaabb Mon Sep 17 00:00:00 2001 From: Robin Olsen <129996395+Telikz@users.noreply.github.com> Date: Sun, 1 Mar 2026 20:54:27 +0100 Subject: [PATCH 3/3] Update internal/commands/issues/close.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- internal/commands/issues/close.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/commands/issues/close.go b/internal/commands/issues/close.go index 0665fe8..3c89b10 100644 --- a/internal/commands/issues/close.go +++ b/internal/commands/issues/close.go @@ -14,7 +14,6 @@ var CloseCmd = &cobra.Command{ Short: "Close an existing issue", Long: `Close an existing issue by its ID.`, Example: `pm close pm-abc`, - Args: cobra.ExactArgs(1), RunE: runCloseCmd,