MCPcopy
hub / github.com/cli/cli / NewCmdView

Function NewCmdView

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

Source from the content-addressed store, hash-verified

34}
35
36func NewCmdView(f *cmdutil.Factory, runF func(*ViewOptions) error) *cobra.Command {
37 opts := &ViewOptions{
38 IO: f.IOStreams,
39 HttpClient: f.HttpClient,
40 Browser: f.Browser,
41 Prompter: f.Prompter,
42 }
43
44 cmd := &cobra.Command{
45 Use: "view [<ruleset-id>]",
46 Short: "View information about a ruleset",
47 Long: heredoc.Docf(`
48 View information about a GitHub ruleset.
49
50 If no ID is provided, an interactive prompt will be used to choose
51 the ruleset to view.
52
53 Use the %[1]s--parents%[1]s flag to control whether rulesets configured at higher
54 levels that also apply to the provided repository or organization should
55 be returned. The default is %[1]strue%[1]s.
56 `, "`"),
57 Example: heredoc.Doc(`
58 # Interactively choose a ruleset to view from all rulesets that apply to the current repository
59 $ gh ruleset view
60
61 # Interactively choose a ruleset to view from only rulesets configured in the current repository
62 $ gh ruleset view --no-parents
63
64 # View a ruleset configured in the current repository or any of its parents
65 $ gh ruleset view 43
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 if repoOverride, _ := cmd.Flags().GetString("repo"); repoOverride != "" && opts.Organization != "" {
76 return cmdutil.FlagErrorf("only one of --repo and --org may be specified")
77 }
78
79 // support `-R, --repo` override
80 opts.BaseRepo = f.BaseRepo
81
82 if len(args) > 0 {
83 // a string is actually needed later on, so verify that it's numeric
84 // but use the string anyway
85 _, err := strconv.Atoi(args[0])
86 if err != nil {
87 return cmdutil.FlagErrorf("invalid value for ruleset ID: %v is not an integer", args[0])
88 }
89 opts.ID = args[0]
90 } else if !opts.IO.CanPrompt() {
91 return cmdutil.FlagErrorf("a ruleset ID must be provided when not running interactively")
92 } else {
93 opts.InteractiveMode = true

Callers 1

Test_NewCmdViewFunction · 0.70

Calls 3

FlagErrorfFunction · 0.92
CanPromptMethod · 0.80
viewRunFunction · 0.70

Tested by 1

Test_NewCmdViewFunction · 0.56