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

Function PromptMissing

pkg/cmd/project/variables/include/include.go:140–186  ·  view source on GitHub ↗
(opts *IncludeOptions)

Source from the content-addressed store, hash-verified

138}
139
140func PromptMissing(opts *IncludeOptions) error {
141 var project *projects.Project
142 var err error
143 if opts.Project.Value == "" {
144 project, err = projectSelector("You have not specified a Project. Please select one:", opts.GetAllProjectsCallback, opts.Ask)
145 if err != nil {
146 return nil
147 }
148 opts.Project.Value = project.GetName()
149 } else {
150 project, err = opts.GetProjectCallback(opts.Project.Value)
151 if err != nil {
152 return err
153 }
154 }
155
156 libraryVariableSets, err := opts.GetAllLibraryVariableSetsCallback()
157
158 unlinkedVariableSets := util.SliceExcept(libraryVariableSets, func(item *variables.LibraryVariableSet) bool {
159 return util.SliceContains(project.IncludedLibraryVariableSets, item.ID)
160 })
161
162 if util.Empty(unlinkedVariableSets) {
163 return fmt.Errorf("no library variable sets available to include")
164 }
165
166 if util.Empty(opts.VariableSets.Value) {
167 selectedVariableSets, err := question.MultiSelectMap(
168 opts.Ask,
169 "Select the Library Variable Sets to include in the project",
170 unlinkedVariableSets,
171 func(item *variables.LibraryVariableSet) string {
172 return item.Name
173 }, false)
174
175 if err != nil {
176 return err
177 }
178
179 if util.Empty(selectedVariableSets) {
180 return fmt.Errorf("no library variable sets selected")
181 }
182 opts.VariableSets.Value = util.SliceTransform(selectedVariableSets, func(item *variables.LibraryVariableSet) string { return item.Name })
183 }
184
185 return nil
186}
187
188func projectSelector(questionText string, getAllProjectsCallback shared.GetAllProjectsCallback, ask question.Asker) (*projects.Project, error) {
189 existingProjects, err := getAllProjectsCallback()

Callers 1

includeRunFunction · 0.70

Calls 7

SliceExceptFunction · 0.92
SliceContainsFunction · 0.92
EmptyFunction · 0.92
MultiSelectMapFunction · 0.92
SliceTransformFunction · 0.92
projectSelectorFunction · 0.70
GetNameMethod · 0.65

Tested by

no test coverage detected