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

Function NewCmdSet

pkg/cmd/variable/set/set.go:44–141  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*SetOptions) error)

Source from the content-addressed store, hash-verified

42}
43
44func NewCmdSet(f *cmdutil.Factory, runF func(*SetOptions) error) *cobra.Command {
45 opts := &SetOptions{
46 IO: f.IOStreams,
47 Config: f.Config,
48 HttpClient: f.HttpClient,
49 Prompter: f.Prompter,
50 }
51
52 cmd := &cobra.Command{
53 Use: "set <variable-name>",
54 Short: "Create or update variables",
55 Long: heredoc.Doc(`
56 Set a value for a variable on one of the following levels:
57 - repository (default): available to GitHub Actions runs or Dependabot in a repository
58 - environment: available to GitHub Actions runs for a deployment environment in a repository
59 - organization: available to GitHub Actions runs or Dependabot within an organization
60
61 Organization variable can optionally be restricted to only be available to
62 specific repositories.
63 `),
64 Example: heredoc.Doc(`
65 # Add variable value for the current repository in an interactive prompt
66 $ gh variable set MYVARIABLE
67
68 # Read variable value from an environment variable
69 $ gh variable set MYVARIABLE --body "$ENV_VALUE"
70
71 # Read variable value from a file
72 $ gh variable set MYVARIABLE < myfile.txt
73
74 # Set variable for a deployment environment in the current repository
75 $ gh variable set MYVARIABLE --env myenvironment
76
77 # Set organization-level variable visible to both public and private repositories
78 $ gh variable set MYVARIABLE --org myOrg --visibility all
79
80 # Set organization-level variable visible to specific repositories
81 $ gh variable set MYVARIABLE --org myOrg --repos repo1,repo2,repo3
82
83 # Set multiple variables imported from the ".env" file
84 $ gh variable set -f .env
85 `),
86 Args: cobra.MaximumNArgs(1),
87 RunE: func(cmd *cobra.Command, args []string) error {
88 // support `-R, --repo` override
89 opts.BaseRepo = f.BaseRepo
90
91 if err := cmdutil.MutuallyExclusive("specify only one of `--org` or `--env`", opts.OrgName != "", opts.EnvName != ""); err != nil {
92 return err
93 }
94
95 if err := cmdutil.MutuallyExclusive("specify only one of `--body` or `--env-file`", opts.Body != "", opts.EnvFile != ""); err != nil {
96 return err
97 }
98
99 if len(args) == 0 {
100 if opts.EnvFile == "" {
101 return cmdutil.FlagErrorf("must pass name argument")

Callers 1

TestNewCmdSetFunction · 0.70

Calls 5

MutuallyExclusiveFunction · 0.92
FlagErrorfFunction · 0.92
StringEnumFlagFunction · 0.92
ChangedMethod · 0.80
setRunFunction · 0.70

Tested by 1

TestNewCmdSetFunction · 0.56