MCPcopy
hub / github.com/cli/cli / NewCmdSet

Function NewCmdSet

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

Source from the content-addressed store, hash-verified

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

Callers 1

TestNewCmdSetFunction · 0.70

Calls 4

MutuallyExclusiveFunction · 0.92
FlagErrorfFunction · 0.92
StringEnumFlagFunction · 0.92
setRunFunction · 0.70

Tested by 1

TestNewCmdSetFunction · 0.56