From 446f66070a38b9718357255f8abd66c6acf57c7d Mon Sep 17 00:00:00 2001 From: Heath Stewart Date: Tue, 15 Oct 2024 14:39:21 -0700 Subject: [PATCH] Add filtered content output to docs --- pkg/cmd/gist/list/list.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pkg/cmd/gist/list/list.go b/pkg/cmd/gist/list/list.go index b1e76e52e4d..00a401be425 100644 --- a/pkg/cmd/gist/list/list.go +++ b/pkg/cmd/gist/list/list.go @@ -48,11 +48,17 @@ func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Comman You can use a regular expression to filter the description, file names, or even the content of files in the gist using %[1]s--filter%[1]s. + For supported regular expression syntax, see . + Use %[1]s--include-content%[1]s to include content of files, noting that this will be slower and increase the rate limit used. Instead of printing a table, - code will be printed with highlights. + code will be printed with highlights similar to %[1]sgh search code%[1]s: + + {{gist ID}} {{file name}} + {{description}} + {{matching lines from content}} - For supported regular expression syntax, see + No highlights or other color is printed when output is redirected. `, "`"), Example: heredoc.Doc(` # list all secret gists from your user account @@ -207,6 +213,14 @@ func printTable(io *iostreams.IOStreams, gists []shared.Gist, filter *regexp.Reg return tp.Render() } +// printContent prints a gist with optional description and content similar to `gh search code` +// including highlighted matches in the form: +// +// {{gist ID}} {{file name}} +// {{description, if any}} +// {{content lines with matches, if any}} +// +// If printing to a non-TTY stream the format will be the same but without highlights. func printContent(io *iostreams.IOStreams, gists []shared.Gist, filter *regexp.Regexp) error { const tab string = " " cs := io.ColorScheme()