From d3911ec1f9b3c5f58801a97e2c07703791f063fe Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Thu, 5 Feb 2026 12:48:09 +0100 Subject: [PATCH] add ls command for listing all issues with query and filter tags --- pkg/cli/commands/ls.go | 91 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 pkg/cli/commands/ls.go diff --git a/pkg/cli/commands/ls.go b/pkg/cli/commands/ls.go new file mode 100644 index 0000000..76e68aa --- /dev/null +++ b/pkg/cli/commands/ls.go @@ -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) +}