From 8fa69c491507707c64faa9223bc7678e85dc37ac Mon Sep 17 00:00:00 2001 From: vaindil Date: Tue, 2 May 2023 12:21:57 -0400 Subject: [PATCH] don't allow both --repo and --org, add docs --- pkg/cmd/ruleset/list/list.go | 27 ++++++++++++++++++++++++--- pkg/cmd/ruleset/view/view.go | 4 ++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/pkg/cmd/ruleset/list/list.go b/pkg/cmd/ruleset/list/list.go index ee13afeef..6183adb6a 100644 --- a/pkg/cmd/ruleset/list/list.go +++ b/pkg/cmd/ruleset/list/list.go @@ -43,11 +43,32 @@ func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Comman Use: "list", Short: "List rulesets for a repository or organization", Long: heredoc.Doc(` - TODO + List GitHub rulesets for a repository or organization. + + If no options are provided, the current repository's rulesets are listed. You can query a different + repository's rulesets by using the --repo flag. You can also use the --org flag to list rulesets + configured for the provided organization. + + Use the --parents flag to include rulesets configured at higher levels that also apply to the current repository. + + Your access token must have the admin:org scope, which can be granted by running "gh auth refresh -s admin:org". `), - Example: "TODO", - Args: cobra.ExactArgs(0), + Example: heredoc.Doc(` + # List rulesets in the current repository + $ gh ruleset list + + # List rulesets in a different repository, including those configured at higher levels + $ gh ruleset list --repo owner/repo --parents + + # List rulesets in an organization + $ gh ruleset list --org org-name + `), + Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, args []string) error { + if repoOverride, _ := cmd.Flags().GetString("repo"); repoOverride != "" && opts.Organization != "" { + return cmdutil.FlagErrorf("only one of --repo and --org may be specified") + } + // support `-R, --repo` override opts.BaseRepo = f.BaseRepo diff --git a/pkg/cmd/ruleset/view/view.go b/pkg/cmd/ruleset/view/view.go index 7569d3e62..fca7b17bf 100644 --- a/pkg/cmd/ruleset/view/view.go +++ b/pkg/cmd/ruleset/view/view.go @@ -60,6 +60,10 @@ func NewCmdView(f *cmdutil.Factory, runF func(*ViewOptions) error) *cobra.Comman `), Args: cobra.MaximumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { + if repoOverride, _ := cmd.Flags().GetString("repo"); repoOverride != "" && opts.Organization != "" { + return cmdutil.FlagErrorf("only one of --repo and --org may be specified") + } + // support `-R, --repo` override opts.BaseRepo = f.BaseRepo