MCPcopy
hub / github.com/cli/cli / NewCmdRepos

Function NewCmdRepos

pkg/cmd/search/repos/repos.go:29–129  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*ReposOptions) error)

Source from the content-addressed store, hash-verified

27}
28
29func NewCmdRepos(f *cmdutil.Factory, runF func(*ReposOptions) error) *cobra.Command {
30 var order string
31 var sort string
32 opts := &ReposOptions{
33 Browser: f.Browser,
34 IO: f.IOStreams,
35 Query: search.Query{Kind: search.KindRepositories},
36 }
37
38 cmd := &cobra.Command{
39 Use: "repos [<query>]",
40 Short: "Search for repositories",
41 Long: heredoc.Docf(`
42 Search for repositories on GitHub.
43
44 The command supports constructing queries using the GitHub search syntax,
45 using the parameter and qualifier flags, or a combination of the two.
46
47 GitHub search syntax is documented at:
48 <https://docs.github.com/search-github/searching-on-github/searching-for-repositories>
49
50 For more information on handling search queries containing a hyphen, run %[1]sgh search --help%[1]s.
51 `, "`"),
52 Example: heredoc.Doc(`
53 # Search repositories matching set of keywords "cli" and "shell"
54 $ gh search repos cli shell
55
56 # Search repositories matching phrase "vim plugin"
57 $ gh search repos "vim plugin"
58
59 # Search repositories public repos in the microsoft organization
60 $ gh search repos --owner=microsoft --visibility=public
61
62 # Search repositories with a set of topics
63 $ gh search repos --topic=unix,terminal
64
65 # Search repositories by coding language and number of good first issues
66 $ gh search repos --language=go --good-first-issues=">=10"
67
68 # Search repositories without topic "linux"
69 $ gh search repos -- -topic:linux
70
71 # Search repositories excluding archived repositories
72 $ gh search repos --archived=false
73 `),
74 RunE: func(c *cobra.Command, args []string) error {
75 if len(args) == 0 && c.Flags().NFlag() == 0 {
76 return cmdutil.FlagErrorf("specify search keywords or flags")
77 }
78 if opts.Query.Limit < 1 || opts.Query.Limit > shared.SearchMaxResults {
79 return cmdutil.FlagErrorf("`--limit` must be between 1 and 1000")
80 }
81 if c.Flags().Changed("order") {
82 opts.Query.Order = order
83 }
84 if c.Flags().Changed("sort") {
85 opts.Query.Sort = sort
86 }

Callers 1

TestNewCmdReposFunction · 0.85

Calls 7

FlagErrorfFunction · 0.92
SearcherFunction · 0.92
AddJSONFlagsFunction · 0.92
StringEnumFlagFunction · 0.92
NilBoolFlagFunction · 0.92
StringSliceEnumFlagFunction · 0.92
reposRunFunction · 0.85

Tested by 1

TestNewCmdReposFunction · 0.68