| 32 | } |
| 33 | |
| 34 | func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Command { |
| 35 | opts := &ListOptions{ |
| 36 | IO: f.IOStreams, |
| 37 | HttpClient: f.HttpClient, |
| 38 | Browser: f.Browser, |
| 39 | } |
| 40 | cmd := &cobra.Command{ |
| 41 | Use: "list", |
| 42 | Short: "List rulesets for a repository or organization", |
| 43 | Long: heredoc.Docf(` |
| 44 | List GitHub rulesets for a repository or organization. |
| 45 | |
| 46 | If no options are provided, the current repository's rulesets are listed. You can query a different |
| 47 | repository's rulesets by using the %[1]s--repo%[1]s flag. You can also use the %[1]s--org%[1]s flag to list rulesets |
| 48 | configured for the provided organization. |
| 49 | |
| 50 | Use the %[1]s--parents%[1]s flag to control whether rulesets configured at higher levels that also apply to the provided |
| 51 | repository or organization should be returned. The default is %[1]strue%[1]s. |
| 52 | |
| 53 | Your access token must have the %[1]sadmin:org%[1]s scope to use the %[1]s--org%[1]s flag, which can be granted by running %[1]sgh auth refresh -s admin:org%[1]s. |
| 54 | `, "`"), |
| 55 | Example: heredoc.Doc(` |
| 56 | # List rulesets in the current repository |
| 57 | $ gh ruleset list |
| 58 | |
| 59 | # List rulesets in a different repository, including those configured at higher levels |
| 60 | $ gh ruleset list --repo owner/repo --parents |
| 61 | |
| 62 | # List rulesets in an organization |
| 63 | $ gh ruleset list --org org-name |
| 64 | `), |
| 65 | Aliases: []string{"ls"}, |
| 66 | Args: cobra.ExactArgs(0), |
| 67 | RunE: func(cmd *cobra.Command, args []string) error { |
| 68 | if repoOverride, _ := cmd.Flags().GetString("repo"); repoOverride != "" && opts.Organization != "" { |
| 69 | return cmdutil.FlagErrorf("only one of --repo and --org may be specified") |
| 70 | } |
| 71 | |
| 72 | // support `-R, --repo` override |
| 73 | opts.BaseRepo = f.BaseRepo |
| 74 | |
| 75 | if opts.Limit < 1 { |
| 76 | return cmdutil.FlagErrorf("invalid limit: %v", opts.Limit) |
| 77 | } |
| 78 | |
| 79 | if runF != nil { |
| 80 | return runF(opts) |
| 81 | } |
| 82 | |
| 83 | return listRun(opts) |
| 84 | }, |
| 85 | } |
| 86 | |
| 87 | cmd.Flags().IntVarP(&opts.Limit, "limit", "L", 30, "Maximum number of rulesets to list") |
| 88 | cmd.Flags().StringVarP(&opts.Organization, "org", "o", "", "List organization-wide rulesets for the provided organization") |
| 89 | cmd.Flags().BoolVarP(&opts.IncludeParents, "parents", "p", true, "Whether to include rulesets configured at higher levels that also apply") |
| 90 | cmd.Flags().BoolVarP(&opts.WebMode, "web", "w", false, "Open the list of rulesets in the web browser") |
| 91 | |