Merge branch 'main' into LPM-33
This commit is contained in:
91
pkg/cli/commands/ls.go
Normal file
91
pkg/cli/commands/ls.go
Normal file
@@ -0,0 +1,91 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/internal/models"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
titleFlag string
|
||||
descriptionFlag string
|
||||
statusFlag string
|
||||
typeFlag string
|
||||
priorityFlag int
|
||||
limit int = 25
|
||||
)
|
||||
|
||||
const (
|
||||
lsExamples = `pm ls [id|title|description]
|
||||
pm ls --status open --type bug
|
||||
pm ls --title "New feature" --desc "feature description"
|
||||
pm ls -p 1 -l 10`
|
||||
)
|
||||
|
||||
var getIssuesCmd = &cobra.Command{
|
||||
Use: "ls [search query]",
|
||||
Short: "List all issues",
|
||||
Long: `List all issues in the project management system.`,
|
||||
Aliases: []string{"list", "search"},
|
||||
Example: lsExamples,
|
||||
Args: cobra.MinimumNArgs(0),
|
||||
RunE: runGetIssuesCmd,
|
||||
}
|
||||
|
||||
func runGetIssuesCmd(cmd *cobra.Command, args []string) error {
|
||||
|
||||
queryArg := strings.Join(args, " ")
|
||||
|
||||
filter := models.IssueFilter{
|
||||
TitleSearch: titleFlag,
|
||||
DescriptionContains: descriptionFlag,
|
||||
Limit: limit,
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("status") {
|
||||
s := models.Status(statusFlag)
|
||||
filter.Status = &s
|
||||
}
|
||||
if cmd.Flags().Changed("type") {
|
||||
t := models.IssueType(typeFlag)
|
||||
filter.IssueType = &t
|
||||
}
|
||||
if cmd.Flags().Changed("priority") {
|
||||
filter.Priority = &priorityFlag
|
||||
}
|
||||
|
||||
issuesPtr, err := svc.Beads.SearchIssues(cmd.Context(), queryArg, filter)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
issues := models.IssuesPtrToIssues(issuesPtr)
|
||||
|
||||
models.PrintIssues(issues)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
getIssuesCmd.Flags().StringVar(&titleFlag, "title", "", "Filter issues by title")
|
||||
getIssuesCmd.Flags().StringVarP(&descriptionFlag, "desc", "d", "", "Filter issues by description")
|
||||
getIssuesCmd.Flags().StringVarP(&statusFlag, "status", "s", "", "Filter issues by status (open, closed, in_progress)")
|
||||
getIssuesCmd.Flags().StringVarP(&typeFlag, "type", "t", "", "Filter issues by type (bug, feature, task)")
|
||||
getIssuesCmd.Flags().IntVarP(&priorityFlag, "priority", "p", 0, "Filter issues by priority (0-5)")
|
||||
getIssuesCmd.Flags().IntVarP(&limit, "limit", "l", 25, "Limit the number of issues returned")
|
||||
|
||||
getIssuesCmd.RegisterFlagCompletionFunc("status", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
return []string{"open", "closed", "in_progress"}, cobra.ShellCompDirectiveDefault
|
||||
})
|
||||
|
||||
getIssuesCmd.RegisterFlagCompletionFunc("type", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
return []string{"bug", "feature", "task"}, cobra.ShellCompDirectiveDefault
|
||||
})
|
||||
|
||||
getIssuesCmd.RegisterFlagCompletionFunc("priority", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
return []string{"0", "1", "2", "3", "4", "5"}, cobra.ShellCompDirectiveDefault
|
||||
})
|
||||
|
||||
rootCmd.AddCommand(getIssuesCmd)
|
||||
}
|
||||
66
pkg/cli/commands/read.go
Normal file
66
pkg/cli/commands/read.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var getIssueCmd = &cobra.Command{
|
||||
Use: "describe [issue ID]",
|
||||
Aliases: []string{"get", "read"},
|
||||
Short: "Get issue details",
|
||||
Long: `Get issue details by ID`,
|
||||
RunE: runGetCmd,
|
||||
Args: cobra.ExactArgs(1),
|
||||
ValidArgsFunction: completeIssues,
|
||||
}
|
||||
|
||||
func runGetCmd(cmd *cobra.Command, args []string) error {
|
||||
issueID := args[0]
|
||||
|
||||
issue, err := svc.Beads.GetIssue(cmd.Context(), issueID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if issue == nil {
|
||||
cmd.Printf("Issue with ID '%s' not found\n", issueID)
|
||||
return nil
|
||||
}
|
||||
|
||||
cmd.Printf("Title: %s\n", issue.Title)
|
||||
cmd.Printf("Description: %s\n", issue.Description)
|
||||
cmd.Printf("Status: %s\n", issue.Status)
|
||||
cmd.Printf("Type: %s\n", issue.IssueType)
|
||||
cmd.Printf("Priority: %d\n", issue.Priority)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(getIssueCmd)
|
||||
}
|
||||
|
||||
func completeIssues(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
if svc == nil {
|
||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
|
||||
issues, err := svc.Beads.AllIssues(cmd.Context())
|
||||
if err != nil {
|
||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
|
||||
var completions []string
|
||||
for _, issue := range issues {
|
||||
|
||||
if strings.HasPrefix(issue.ID, toComplete) {
|
||||
completions = append(completions, issue.ID)
|
||||
} else if strings.HasPrefix(issue.Title, toComplete) {
|
||||
completions = append(completions, issue.ID)
|
||||
}
|
||||
}
|
||||
|
||||
return completions, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
@@ -9,13 +9,13 @@ import (
|
||||
var svc *service.Services
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "pm",
|
||||
Short: "Project Management CLI",
|
||||
Long: `Project Management CLI for managing issues and tasks.`,
|
||||
}
|
||||
|
||||
func Execute(services *service.Services) error {
|
||||
svc = services
|
||||
rootCmd.Use = svc.Config.RootCmd
|
||||
return rootCmd.Execute()
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ func init() {
|
||||
rootCmd.AddCommand(createCmd)
|
||||
rootCmd.AddCommand(deleteCmd)
|
||||
rootCmd.CompletionOptions.DisableDefaultCmd = false
|
||||
rootCmd.AddGroup(&cobra.Group{ID: "other", Title: "Helping Commands"})
|
||||
rootCmd.SetCompletionCommandGroupID("other")
|
||||
rootCmd.SetHelpCommandGroupID("other")
|
||||
rootCmd.AddGroup(&cobra.Group{ID: "help", Title: "Helping Commands"})
|
||||
rootCmd.SetCompletionCommandGroupID("help")
|
||||
rootCmd.SetHelpCommandGroupID("help")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user