MCPcopy
hub / github.com/cli/cli / NewCmdCheck

Function NewCmdCheck

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

Source from the content-addressed store, hash-verified

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

Callers 1

Test_NewCmdCheckFunction · 0.85

Calls 2

MutuallyExclusiveFunction · 0.92
checkRunFunction · 0.85

Tested by 1

Test_NewCmdCheckFunction · 0.68