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

Function NewCmdGet

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

Source from the content-addressed store, hash-verified

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