| 29 | } |
| 30 | |
| 31 | func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Command { |
| 32 | opts := &ListOptions{ |
| 33 | IO: f.IOStreams, |
| 34 | Config: f.Config, |
| 35 | HttpClient: f.HttpClient, |
| 36 | } |
| 37 | |
| 38 | var flagPublic bool |
| 39 | var flagSecret bool |
| 40 | var flagFilter string |
| 41 | |
| 42 | cmd := &cobra.Command{ |
| 43 | Use: "list", |
| 44 | Short: "List your gists", |
| 45 | Long: heredoc.Docf(` |
| 46 | List gists from your user account. |
| 47 | |
| 48 | You can use a regular expression to filter the description, file names, |
| 49 | or even the content of files in the gist using %[1]s--filter%[1]s. |
| 50 | |
| 51 | For supported regular expression syntax, see <https://pkg.go.dev/regexp/syntax>. |
| 52 | |
| 53 | Use %[1]s--include-content%[1]s to include content of files, noting that |
| 54 | this will be slower and increase the rate limit used. Instead of printing a table, |
| 55 | code will be printed with highlights similar to %[1]sgh search code%[1]s: |
| 56 | |
| 57 | {{gist ID}} {{file name}} |
| 58 | {{description}} |
| 59 | {{matching lines from content}} |
| 60 | |
| 61 | No highlights or other color is printed when output is redirected. |
| 62 | `, "`"), |
| 63 | Example: heredoc.Doc(` |
| 64 | # List all secret gists from your user account |
| 65 | $ gh gist list --secret |
| 66 | |
| 67 | # Find all gists from your user account mentioning "octo" anywhere |
| 68 | $ gh gist list --filter octo --include-content |
| 69 | `), |
| 70 | Aliases: []string{"ls"}, |
| 71 | Args: cobra.NoArgs, |
| 72 | RunE: func(cmd *cobra.Command, args []string) error { |
| 73 | if opts.Limit < 1 { |
| 74 | return cmdutil.FlagErrorf("invalid limit: %v", opts.Limit) |
| 75 | } |
| 76 | |
| 77 | if flagFilter == "" { |
| 78 | if opts.IncludeContent { |
| 79 | return cmdutil.FlagErrorf("cannot use --include-content without --filter") |
| 80 | } |
| 81 | } else { |
| 82 | if filter, err := regexp.CompilePOSIX(flagFilter); err != nil { |
| 83 | return err |
| 84 | } else { |
| 85 | opts.Filter = filter |
| 86 | } |
| 87 | } |
| 88 | |