MCPcopy
hub / github.com/cli/cli / NewCmdGet

Function NewCmdGet

pkg/cmd/variable/get/get.go:31–70  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*GetOptions) error)

Source from the content-addressed store, hash-verified

29}
30
31func NewCmdGet(f *cmdutil.Factory, runF func(*GetOptions) error) *cobra.Command {
32 opts := &GetOptions{
33 IO: f.IOStreams,
34 Config: f.Config,
35 HttpClient: f.HttpClient,
36 }
37
38 cmd := &cobra.Command{
39 Use: "get <variable-name>",
40 Short: "Get variables",
41 Long: heredoc.Doc(`
42 Get a variable on one of the following levels:
43 - repository (default): available to GitHub Actions runs or Dependabot in a repository
44 - environment: available to GitHub Actions runs for a deployment environment in a repository
45 - organization: available to GitHub Actions runs or Dependabot within an organization
46 `),
47 Args: cobra.ExactArgs(1),
48 RunE: func(cmd *cobra.Command, args []string) error {
49 // support `-R, --repo` override
50 opts.BaseRepo = f.BaseRepo
51
52 if err := cmdutil.MutuallyExclusive("specify only one of `--org` or `--env`", opts.OrgName != "", opts.EnvName != ""); err != nil {
53 return err
54 }
55
56 opts.VariableName = args[0]
57
58 if runF != nil {
59 return runF(opts)
60 }
61
62 return getRun(opts)
63 },
64 }
65 cmd.Flags().StringVarP(&opts.OrgName, "org", "o", "", "Get a variable for an organization")
66 cmd.Flags().StringVarP(&opts.EnvName, "env", "e", "", "Get a variable for an environment")
67 cmdutil.AddJSONFlags(cmd, &opts.Exporter, shared.VariableJSONFields)
68
69 return cmd
70}
71
72func getRun(opts *GetOptions) error {
73 c, err := opts.HttpClient()

Callers 1

TestNewCmdGetFunction · 0.85

Calls 3

MutuallyExclusiveFunction · 0.92
AddJSONFlagsFunction · 0.92
getRunFunction · 0.70

Tested by 1

TestNewCmdGetFunction · 0.68