docs(search): move search syntax note to gh search --help

This commit is contained in:
Sukh 2025-08-02 03:01:40 -04:00
parent 73f6acc709
commit 6e400eb4a1
7 changed files with 33 additions and 35 deletions

View file

@ -304,35 +304,6 @@ var HelpTopics = []helpTopic{
control some behavior.
`),
},
{
name: "search-syntax",
short: "Search syntax for gh commands",
long: heredoc.Docf(`
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
syntax 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>
`, "`", "%"),
},
}
func NewCmdHelpTopic(ios *iostreams.IOStreams, ht helpTopic) *cobra.Command {

View file

@ -47,7 +47,7 @@ func NewCmdCode(f *cmdutil.Factory, runF func(*CodeOptions) error) *cobra.Comman
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 help search-syntax%[1]s.
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"

View file

@ -46,7 +46,7 @@ func NewCmdCommits(f *cmdutil.Factory, runF func(*CommitsOptions) error) *cobra.
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 help search-syntax%[1]s.
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"

View file

@ -35,7 +35,7 @@ func NewCmdIssues(f *cmdutil.Factory, runF func(*shared.IssuesOptions) error) *c
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 help search-syntax%[1]s.
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"

View file

@ -37,7 +37,7 @@ func NewCmdPrs(f *cmdutil.Factory, runF func(*shared.IssuesOptions) error) *cobr
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 help search-syntax%[1]s.
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"

View file

@ -47,7 +47,7 @@ func NewCmdRepos(f *cmdutil.Factory, runF func(*ReposOptions) error) *cobra.Comm
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 help search-syntax%[1]s.
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"

View file

@ -3,6 +3,7 @@ package search
import (
"github.com/cli/cli/v2/pkg/cmdutil"
"github.com/spf13/cobra"
"github.com/MakeNowJust/heredoc"
searchCodeCmd "github.com/cli/cli/v2/pkg/cmd/search/code"
searchCommitsCmd "github.com/cli/cli/v2/pkg/cmd/search/commits"
@ -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
syntax 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))