MCPcopy Create free account
hub / github.com/OctopusDeploy/cli / NewCreateCmd

Function NewCreateCmd

pkg/cmd/project/variables/create/create.go:110–149  ·  view source on GitHub ↗
(f factory.Factory)

Source from the content-addressed store, hash-verified

108}
109
110func NewCreateCmd(f factory.Factory) *cobra.Command {
111 createFlags := NewCreateFlags()
112 cmd := &cobra.Command{
113 Use: "create",
114 Short: "Create a variable for a project",
115 Long: "Create a variable for a project in Octopus Deploy",
116 Aliases: []string{"add"},
117 Example: heredoc.Docf(`
118 %[1]s project variable create
119 %[1]s project variable create --project "Deploy Website" --name "variable name" --value "abc"
120 %[1]s project variable create --name "variable name" --value "passwordABC" --type sensitive
121 %[1]s project variable create --name "variable name" --value "abc" --scope environment='test'
122 %[1]s project variable create --name "variable name" --value "abc" --scope environment='test' --git-ref refs/heads/main
123 `, constants.ExecutableName),
124 RunE: func(c *cobra.Command, args []string) error {
125 opts := NewCreateOptions(createFlags, cmd.NewDependencies(f, c))
126 if opts.Type.Value == TypeSensitive {
127 opts.Value.Secure = true
128 }
129
130 return CreateRun(opts)
131 },
132 }
133
134 flags := cmd.Flags()
135 flags.StringVarP(&createFlags.Project.Value, createFlags.Project.Name, "p", "", "The project")
136 flags.StringVarP(&createFlags.Name.Value, createFlags.Name.Name, "n", "", "The name of the variable")
137 flags.StringVarP(&createFlags.Type.Value, createFlags.Type.Name, "t", "", fmt.Sprintf("The type of variable. Valid values are %s. Default is %s", strings.Join([]string{TypeText, TypeSensitive, TypeWorkerPool, TypeAwsAccount, TypeAzureAccount, TypeGoogleAccount, TypeCertificate}, ", "), TypeText))
138 flags.StringVar(&createFlags.Value.Value, createFlags.Value.Name, "", "The value to set on the variable")
139 flags.StringVarP(&createFlags.GitRef.Value, createFlags.GitRef.Name, "", "", "The GitRef for the Config-As-Code branch")
140
141 sharedProjectVariable.RegisterScopeFlags(cmd, createFlags.ScopeFlags)
142 flags.BoolVar(&createFlags.IsPrompted.Value, createFlags.IsPrompted.Name, false, "Make a prompted variable")
143 flags.StringVar(&createFlags.PromptLabel.Value, createFlags.PromptLabel.Name, "", "The label for the prompted variable")
144 flags.StringVar(&createFlags.PromptDescription.Value, createFlags.PromptDescription.Name, "", "Description for the prompted variable")
145 flags.StringVar(&createFlags.PromptType.Value, createFlags.PromptType.Name, "", fmt.Sprintf("The input type for the prompted variable. Valid values are '%s', '%s', '%s' and '%s'", PromptTypeText, PromptTypeMultiText, PromptTypeCheckbox, PromptTypeDropdown))
146 flags.BoolVar(&createFlags.PromptRequired.Value, createFlags.PromptRequired.Name, false, "Prompt will require a value for deployment")
147 flags.StringSliceVar(&createFlags.PromptSelectOptions.Value, createFlags.PromptSelectOptions.Name, []string{}, "Options for a dropdown prompt. May be specified multiple times. Must be in format 'value|description'")
148 return cmd
149}
150
151func CreateRun(opts *CreateOptions) error {
152 if !opts.NoPrompt {

Callers

nothing calls this directly

Calls 3

NewCreateFlagsFunction · 0.70
NewCreateOptionsFunction · 0.70
CreateRunFunction · 0.70

Tested by

no test coverage detected