refactor to make cli better and simplify the code

This commit is contained in:
Robin Olsen
2026-03-01 20:42:56 +01:00
parent a266ce5464
commit 9612cb9338
32 changed files with 182 additions and 255 deletions

View File

@@ -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,

View File

@@ -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,

View File

@@ -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.`,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,
}

View File

@@ -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")
}

View File

@@ -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`,