MCPcopy
hub / github.com/cli/cli / NewCmdList

Function NewCmdList

pkg/cmd/discussion/list/list.go:82–148  ·  view source on GitHub ↗

NewCmdList creates the "discussion list" command.

(f *cmdutil.Factory, runF func(*ListOptions) error)

Source from the content-addressed store, hash-verified

80
81// NewCmdList creates the "discussion list" command.
82func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Command {
83 opts := &ListOptions{
84 IO: f.IOStreams,
85 Browser: f.Browser,
86 Now: time.Now,
87 }
88
89 cmd := &cobra.Command{
90 Use: "list [flags]",
91 Short: "List discussions in a repository (preview)",
92 Long: heredoc.Doc(`
93 List discussions in a GitHub repository. By default, only open discussions
94 are shown.
95 `),
96 Example: heredoc.Doc(`
97 # List open discussions
98 $ gh discussion list
99
100 # List discussions with a specific category
101 $ gh discussion list --category General
102
103 # List closed discussions by author
104 $ gh discussion list --state closed --author monalisa
105
106 # List all discussions (closed or open) by label
107 $ gh discussion list --state all --label bug,enhancement
108
109 # List answered Q&A discussions as JSON
110 $ gh discussion list --answered --json number,title,url
111
112 # List unanswered Q&A discussions as JSON
113 $ gh discussion list --answered=false --json number,title,url
114 `),
115 Aliases: []string{"ls"},
116 Args: cmdutil.NoArgsQuoteReminder,
117 RunE: func(cmd *cobra.Command, args []string) error {
118 opts.BaseRepo = f.BaseRepo
119 opts.Client = shared.DiscussionClientFunc(f)
120
121 if opts.Limit < 1 {
122 return cmdutil.FlagErrorf("invalid limit: %v", opts.Limit)
123 }
124
125 if runF != nil {
126 return runF(opts)
127 }
128 return listRun(opts)
129 },
130 }
131
132 cmdutil.EnableRepoOverride(cmd, f)
133
134 cmd.Flags().StringVarP(&opts.Author, "author", "A", "", "Filter by author")
135 cmd.Flags().StringVarP(&opts.Category, "category", "c", "", "Filter by category name or slug")
136 cmd.Flags().StringSliceVarP(&opts.Labels, "label", "l", nil, "Filter by label")
137 cmdutil.StringEnumFlag(cmd, &opts.State, "state", "s", stateOpen, []string{stateOpen, stateClosed, stateAll}, "Filter by state")
138 cmd.Flags().IntVarP(&opts.Limit, "limit", "L", defaultLimit, "Maximum number of discussions to fetch")
139 cmdutil.NilBoolFlag(cmd, &opts.Answered, "answered", "", "Filter by answered state")

Callers 1

TestNewCmdListFunction · 0.70

Calls 7

DiscussionClientFuncFunction · 0.92
FlagErrorfFunction · 0.92
EnableRepoOverrideFunction · 0.92
StringEnumFlagFunction · 0.92
NilBoolFlagFunction · 0.92
AddJSONFlagsFunction · 0.92
listRunFunction · 0.70

Tested by 1

TestNewCmdListFunction · 0.56