Skip to content

Commit cf1e14c

Browse files
authored
Merge pull request cli#11162 from Sukhpreet-s/10480-enhance-gh-search-docs
Adding a note to `gh search` docs to explain the usage of `--` to exclude certain results
2 parents cf7c2b9 + b5a6913 commit cf1e14c

6 files changed

Lines changed: 46 additions & 9 deletions

File tree

pkg/cmd/search/code/code.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ func NewCmdCode(f *cmdutil.Factory, runF func(*CodeOptions) error) *cobra.Comman
4646
Note that these search results are powered by what is now a legacy GitHub code search engine.
4747
The results might not match what is seen on %[1]sgithub.com%[1]s, and new features like regex search
4848
are not yet available via the GitHub API.
49+
50+
For more information on handling search queries containing a hyphen, run %[1]sgh search --help%[1]s.
4951
`, "`"),
5052
Example: heredoc.Doc(`
5153
# Search code matching "react" and "lifecycle"

pkg/cmd/search/commits/commits.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,17 @@ func NewCmdCommits(f *cmdutil.Factory, runF func(*CommitsOptions) error) *cobra.
3737
cmd := &cobra.Command{
3838
Use: "commits [<query>]",
3939
Short: "Search for commits",
40-
Long: heredoc.Doc(`
40+
Long: heredoc.Docf(`
4141
Search for commits on GitHub.
4242
4343
The command supports constructing queries using the GitHub search syntax,
4444
using the parameter and qualifier flags, or a combination of the two.
4545
4646
GitHub search syntax is documented at:
4747
<https://docs.github.com/search-github/searching-on-github/searching-commits>
48-
`),
48+
49+
For more information on handling search queries containing a hyphen, run %[1]sgh search --help%[1]s.
50+
`, "`"),
4951
Example: heredoc.Doc(`
5052
# Search commits matching set of keywords "readme" and "typo"
5153
$ gh search commits readme typo

pkg/cmd/search/issues/issues.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,17 @@ func NewCmdIssues(f *cmdutil.Factory, runF func(*shared.IssuesOptions) error) *c
2626
cmd := &cobra.Command{
2727
Use: "issues [<query>]",
2828
Short: "Search for issues",
29-
Long: heredoc.Doc(`
29+
Long: heredoc.Docf(`
3030
Search for issues on GitHub.
3131
3232
The command supports constructing queries using the GitHub search syntax,
3333
using the parameter and qualifier flags, or a combination of the two.
3434
3535
GitHub search syntax is documented at:
3636
<https://docs.github.com/search-github/searching-on-github/searching-issues-and-pull-requests>
37-
`),
37+
38+
For more information on handling search queries containing a hyphen, run %[1]sgh search --help%[1]s.
39+
`, "`"),
3840
Example: heredoc.Doc(`
3941
# Search issues matching set of keywords "readme" and "typo"
4042
$ gh search issues readme typo

pkg/cmd/search/prs/prs.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,17 @@ func NewCmdPrs(f *cmdutil.Factory, runF func(*shared.IssuesOptions) error) *cobr
2828
cmd := &cobra.Command{
2929
Use: "prs [<query>]",
3030
Short: "Search for pull requests",
31-
Long: heredoc.Doc(`
31+
Long: heredoc.Docf(`
3232
Search for pull requests on GitHub.
3333
3434
The command supports constructing queries using the GitHub search syntax,
3535
using the parameter and qualifier flags, or a combination of the two.
3636
3737
GitHub search syntax is documented at:
3838
<https://docs.github.com/search-github/searching-on-github/searching-issues-and-pull-requests>
39-
`),
39+
40+
For more information on handling search queries containing a hyphen, run %[1]sgh search --help%[1]s.
41+
`, "`"),
4042
Example: heredoc.Doc(`
4143
# Search pull requests matching set of keywords "fix" and "bug"
4244
$ gh search prs fix bug

pkg/cmd/search/repos/repos.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,17 @@ func NewCmdRepos(f *cmdutil.Factory, runF func(*ReposOptions) error) *cobra.Comm
3838
cmd := &cobra.Command{
3939
Use: "repos [<query>]",
4040
Short: "Search for repositories",
41-
Long: heredoc.Doc(`
41+
Long: heredoc.Docf(`
4242
Search for repositories on GitHub.
4343
4444
The command supports constructing queries using the GitHub search syntax,
4545
using the parameter and qualifier flags, or a combination of the two.
4646
4747
GitHub search syntax is documented at:
4848
<https://docs.github.com/search-github/searching-on-github/searching-for-repositories>
49-
`),
49+
50+
For more information on handling search queries containing a hyphen, run %[1]sgh search --help%[1]s.
51+
`, "`"),
5052
Example: heredoc.Doc(`
5153
# Search repositories matching set of keywords "cli" and "shell"
5254
$ gh search repos cli shell

pkg/cmd/search/search.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package search
22

33
import (
4+
"github.com/MakeNowJust/heredoc"
45
"github.com/cli/cli/v2/pkg/cmdutil"
56
"github.com/spf13/cobra"
67

@@ -15,7 +16,33 @@ func NewCmdSearch(f *cmdutil.Factory) *cobra.Command {
1516
cmd := &cobra.Command{
1617
Use: "search <command>",
1718
Short: "Search for repositories, issues, and pull requests",
18-
Long: "Search across all of GitHub.",
19+
Long: heredoc.Docf(`
20+
Search across all of GitHub.
21+
22+
Excluding search results that match a qualifier
23+
24+
In a browser, the GitHub search syntax supports excluding results that match a search qualifier
25+
by prefixing the qualifier with a hyphen. For example, to search for issues that
26+
do not have the label "bug", you would use %[1]s-label:bug%[1]s as a search qualifier.
27+
28+
%[1]sgh%[1]s supports this syntax in %[1]sgh search%[1]s as well, but it requires extra
29+
command line arguments to avoid the hyphen being interpreted as a command line flag because it begins with a hyphen.
30+
31+
On Unix-like systems, you can use the %[1]s--%[1]s argument to indicate that
32+
the arguments that follow are not a flag, but rather a query string. For example:
33+
34+
$ gh search issues -- "my-search-query -label:bug"
35+
36+
On PowerShell, you must use both the %[1]s--%[2]s%[1]s argument and the %[1]s--%[1]s argument to
37+
produce the same effect. For example:
38+
39+
$ gh --%[2]s search issues -- "my search query -label:bug"
40+
41+
See the following for more information:
42+
- GitHub search syntax: <https://docs.github.com/en/search-github/getting-started-with-searching-on-github/understanding-the-search-syntax#exclude-results-that-match-a-qualifier>
43+
- The PowerShell stop parse flag %[1]s--%[2]s%[1]s: <https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_parsing?view=powershell-7.5#the-stop-parsing-token>
44+
- The Unix-like %[1]s--%[1]s argument: <https://www.gnu.org/software/bash/manual/bash.html#Shell-Builtin-Commands-1>
45+
`, "`", "%"),
1946
}
2047

2148
cmd.AddCommand(searchCodeCmd.NewCmdCode(f, nil))

0 commit comments

Comments
 (0)