MCPcopy Create free account
hub / github.com/cli/cli / NewCmdCheck

Function NewCmdCheck

pkg/cmd/ruleset/check/check.go:36–103  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*CheckOptions) error)

Source from the content-addressed store, hash-verified

34}
35
36func NewCmdCheck(f *cmdutil.Factory, runF func(*CheckOptions) error) *cobra.Command {
37 opts := &CheckOptions{
38 IO: f.IOStreams,
39 Config: f.Config,
40 HttpClient: f.HttpClient,
41 Browser: f.Browser,
42 Git: f.GitClient,
43 }
44 cmd := &cobra.Command{
45 Use: "check [<branch>]",
46 Short: "View rules that would apply to a given branch",
47 Long: heredoc.Docf(`
48 View information about GitHub rules that apply to a given branch.
49
50 The provided branch name does not need to exist; rules will be displayed that would apply
51 to a branch with that name. All rules are returned regardless of where they are configured.
52
53 If no branch name is provided, then the current branch will be used.
54
55 The %[1]s--default%[1]s flag can be used to view rules that apply to the default branch of the
56 repository.
57 `, "`"),
58 Example: heredoc.Doc(`
59 # View all rules that apply to the current branch
60 $ gh ruleset check
61
62 # View all rules that apply to a branch named "my-branch" in a different repository
63 $ gh ruleset check my-branch --repo owner/repo
64
65 # View all rules that apply to the default branch in a different repository
66 $ gh ruleset check --default --repo owner/repo
67
68 # View a ruleset configured in a different repository or any of its parents
69 $ gh ruleset view 23 --repo owner/repo
70
71 # View an organization-level ruleset
72 $ gh ruleset view 23 --org my-org
73 `),
74 Args: cobra.MaximumNArgs(1),
75 RunE: func(cmd *cobra.Command, args []string) error {
76 // support `-R, --repo` override
77 opts.BaseRepo = f.BaseRepo
78
79 if len(args) > 0 {
80 opts.Branch = args[0]
81 }
82
83 if err := cmdutil.MutuallyExclusive(
84 "specify only one of `--default` or a branch name",
85 opts.Branch != "",
86 opts.Default,
87 ); err != nil {
88 return err
89 }
90
91 if runF != nil {
92 return runF(opts)
93 }

Callers 1

Test_NewCmdCheckFunction · 0.85

Calls 2

MutuallyExclusiveFunction · 0.92
checkRunFunction · 0.85

Tested by 1

Test_NewCmdCheckFunction · 0.68