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

Function createRun

pkg/cmd/environment/create/create.go:89–133  ·  view source on GitHub ↗
(opts *CreateOptions)

Source from the content-addressed store, hash-verified

87}
88
89func createRun(opts *CreateOptions) error {
90 if !opts.NoPrompt {
91 err := PromptMissing(opts)
92 if err != nil {
93 return err
94 }
95 } else {
96 // Validate tags when running with --no-prompt
97 if len(opts.Tag.Value) > 0 {
98 tagSets, err := opts.GetAllTagsCallback()
99 if err != nil {
100 return err
101 }
102 if err := selectors.ValidateTags(opts.Tag.Value, tagSets); err != nil {
103 return err
104 }
105 }
106 }
107
108 env := environments.NewEnvironment(opts.Name.Value)
109 env.Description = opts.Description.Value
110 env.AllowDynamicInfrastructure = opts.DynamicInfrastructure.Value
111 env.UseGuidedFailure = opts.GuidedFailureMode.Value
112 env.EnvironmentTags = opts.Tag.Value
113
114 createEnv, err := opts.Client.Environments.Add(env)
115 if err != nil {
116 return err
117 }
118
119 _, err = fmt.Fprintf(opts.Out, "\nSuccessfully created environment '%s' (%s).\n", createEnv.Name, createEnv.ID)
120 if err != nil {
121 return err
122 }
123
124 link := output.Bluef("%s/app#/%s/infrastructure/environments/%s", opts.Host, opts.Space.GetID(), createEnv.GetID())
125 fmt.Fprintf(opts.Out, "View this environment on Octopus Deploy: %s\n", link)
126
127 if !opts.NoPrompt {
128 autoCmd := flag.GenerateAutomationCmd(opts.CmdPath, opts.GetSpaceNameOrEmpty(), opts.Name, opts.Description, opts.GuidedFailureMode, opts.DynamicInfrastructure, opts.Tag)
129 fmt.Fprintf(opts.Out, "%s\n", autoCmd)
130 }
131
132 return nil
133}
134
135func PromptMissing(opts *CreateOptions) error {
136 err := question.AskName(opts.Ask, "", "environment", &opts.Name.Value)

Callers 1

NewCmdCreateFunction · 0.70

Calls 5

ValidateTagsFunction · 0.92
BluefFunction · 0.92
GenerateAutomationCmdFunction · 0.92
GetSpaceNameOrEmptyMethod · 0.80
PromptMissingFunction · 0.70

Tested by

no test coverage detected