Skip to content
2 changes: 2 additions & 0 deletions pkg/cmd/search/code/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func NewCmdCode(f *cmdutil.Factory, runF func(*CodeOptions) error) *cobra.Comman
Note that these search results are powered by what is now a legacy GitHub code search engine.
The results might not match what is seen on %[1]sgithub.com%[1]s, and new features like regex search
are not yet available via the GitHub API.

For more information on handling search queries containing a hyphen, run %[1]sgh search --help%[1]s.
`, "`"),
Example: heredoc.Doc(`
# Search code matching "react" and "lifecycle"
Expand Down
6 changes: 4 additions & 2 deletions pkg/cmd/search/commits/commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@ func NewCmdCommits(f *cmdutil.Factory, runF func(*CommitsOptions) error) *cobra.
cmd := &cobra.Command{
Use: "commits [<query>]",
Short: "Search for commits",
Long: heredoc.Doc(`
Long: heredoc.Docf(`
Search for commits on GitHub.

The command supports constructing queries using the GitHub search syntax,
using the parameter and qualifier flags, or a combination of the two.

GitHub search syntax is documented at:
<https://docs.github.com/search-github/searching-on-github/searching-commits>
`),

For more information on handling search queries containing a hyphen, run %[1]sgh search --help%[1]s.
`, "`"),
Example: heredoc.Doc(`
# Search commits matching set of keywords "readme" and "typo"
$ gh search commits readme typo
Expand Down
6 changes: 4 additions & 2 deletions pkg/cmd/search/issues/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ func NewCmdIssues(f *cmdutil.Factory, runF func(*shared.IssuesOptions) error) *c
cmd := &cobra.Command{
Use: "issues [<query>]",
Short: "Search for issues",
Long: heredoc.Doc(`
Long: heredoc.Docf(`
Search for issues on GitHub.

The command supports constructing queries using the GitHub search syntax,
using the parameter and qualifier flags, or a combination of the two.

GitHub search syntax is documented at:
<https://docs.github.com/search-github/searching-on-github/searching-issues-and-pull-requests>
`),

For more information on handling search queries containing a hyphen, run %[1]sgh search --help%[1]s.
`, "`"),
Example: heredoc.Doc(`
# Search issues matching set of keywords "readme" and "typo"
$ gh search issues readme typo
Expand Down
6 changes: 4 additions & 2 deletions pkg/cmd/search/prs/prs.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ func NewCmdPrs(f *cmdutil.Factory, runF func(*shared.IssuesOptions) error) *cobr
cmd := &cobra.Command{
Use: "prs [<query>]",
Short: "Search for pull requests",
Long: heredoc.Doc(`
Long: heredoc.Docf(`
Search for pull requests on GitHub.

The command supports constructing queries using the GitHub search syntax,
using the parameter and qualifier flags, or a combination of the two.

GitHub search syntax is documented at:
<https://docs.github.com/search-github/searching-on-github/searching-issues-and-pull-requests>
`),

For more information on handling search queries containing a hyphen, run %[1]sgh search --help%[1]s.
`, "`"),
Example: heredoc.Doc(`
# Search pull requests matching set of keywords "fix" and "bug"
$ gh search prs fix bug
Expand Down
6 changes: 4 additions & 2 deletions pkg/cmd/search/repos/repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,17 @@ func NewCmdRepos(f *cmdutil.Factory, runF func(*ReposOptions) error) *cobra.Comm
cmd := &cobra.Command{
Use: "repos [<query>]",
Short: "Search for repositories",
Long: heredoc.Doc(`
Long: heredoc.Docf(`
Search for repositories on GitHub.

The command supports constructing queries using the GitHub search syntax,
using the parameter and qualifier flags, or a combination of the two.

GitHub search syntax is documented at:
<https://docs.github.com/search-github/searching-on-github/searching-for-repositories>
`),

For more information on handling search queries containing a hyphen, run %[1]sgh search --help%[1]s.
`, "`"),
Example: heredoc.Doc(`
# Search repositories matching set of keywords "cli" and "shell"
$ gh search repos cli shell
Expand Down
29 changes: 28 additions & 1 deletion pkg/cmd/search/search.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package search

import (
"github.com/MakeNowJust/heredoc"
"github.com/cli/cli/v2/pkg/cmdutil"
"github.com/spf13/cobra"

Expand All @@ -15,7 +16,33 @@ func NewCmdSearch(f *cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{
Use: "search <command>",
Short: "Search for repositories, issues, and pull requests",
Long: "Search across all of GitHub.",
Long: heredoc.Docf(`
Search across all of GitHub.

Excluding search results that match a qualifier

In a browser, the GitHub search syntax supports excluding results that match a search qualifier
by prefixing the qualifier with a hyphen. For example, to search for issues that
do not have the label "bug", you would use %[1]s-label:bug%[1]s as a search qualifier.

%[1]sgh%[1]s supports this syntax in %[1]sgh search%[1]s as well, but it requires extra
command line arguments to avoid the hyphen being interpreted as a command line flag because it begins with a hyphen.

On Unix-like systems, you can use the %[1]s--%[1]s argument to indicate that
the arguments that follow are not a flag, but rather a query string. For example:

$ gh search issues -- "my-search-query -label:bug"

On PowerShell, you must use both the %[1]s--%[2]s%[1]s argument and the %[1]s--%[1]s argument to
produce the same effect. For example:

$ gh --%[2]s search issues -- "my search query -label:bug"

See the following for more information:
- 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>
- 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>
- The Unix-like %[1]s--%[1]s argument: <https://www.gnu.org/software/bash/manual/bash.html#Shell-Builtin-Commands-1>
`, "`", "%"),
}

cmd.AddCommand(searchCodeCmd.NewCmdCode(f, nil))
Expand Down
Loading