github.com/jenkins-x/jx/v2@v2.1.155/pkg/cmd/get/get_issues.go (about) 1 package get 2 3 import ( 4 "github.com/jenkins-x/jx/v2/pkg/cmd/helper" 5 6 "github.com/spf13/cobra" 7 8 "github.com/jenkins-x/jx/v2/pkg/cmd/opts" 9 "github.com/jenkins-x/jx/v2/pkg/cmd/templates" 10 ) 11 12 // GetIssuesOptions contains the command line options 13 type GetIssuesOptions struct { 14 Options 15 Dir string 16 Filter string 17 } 18 19 var ( 20 GetIssuesLong = templates.LongDesc(` 21 Display one or more issues for a project. 22 23 `) 24 25 GetIssuesExample = templates.Examples(` 26 # List open issues on the current project 27 jx get issues 28 `) 29 ) 30 31 // NewCmdGetIssues creates the command 32 func NewCmdGetIssues(commonOpts *opts.CommonOptions) *cobra.Command { 33 options := &GetIssuesOptions{ 34 Options: Options{ 35 CommonOptions: commonOpts, 36 }, 37 } 38 39 cmd := &cobra.Command{ 40 Use: "issues [flags]", 41 Short: "Display one or more issues", 42 Long: GetIssuesLong, 43 Example: GetIssuesExample, 44 Aliases: []string{"jira"}, 45 Run: func(cmd *cobra.Command, args []string) { 46 options.Cmd = cmd 47 options.Args = args 48 err := options.Run() 49 helper.CheckErr(err) 50 }, 51 } 52 cmd.Flags().StringVarP(&options.Dir, "dir", "d", "", "The root project directory") 53 cmd.Flags().StringVarP(&options.Filter, "filter", "", "open", "The filter to use") 54 options.AddGetFlags(cmd) 55 return cmd 56 } 57 58 // Run implements this command 59 func (o *GetIssuesOptions) Run() error { 60 tracker, err := o.CreateIssueProvider(o.Dir) 61 if err != nil { 62 return err 63 } 64 65 issues, err := tracker.SearchIssues(o.Filter) 66 if err != nil { 67 return err 68 } 69 70 table := o.CreateTable() 71 table.AddRow("ISSUE", "TITLE") 72 for _, i := range issues { 73 table.AddRow(i.URL, i.Title) 74 } 75 table.Render() 76 return nil 77 }