(opts *IncludeOptions)
| 83 | } |
| 84 | |
| 85 | func includeRun(opts *IncludeOptions) error { |
| 86 | if !opts.NoPrompt { |
| 87 | err := PromptMissing(opts) |
| 88 | if err != nil { |
| 89 | return err |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | project, err := opts.GetProjectCallback(opts.Project.Value) |
| 94 | if err != nil { |
| 95 | return err |
| 96 | } |
| 97 | |
| 98 | libraryVariableSets, err := opts.GetAllLibraryVariableSetsCallback() |
| 99 | if err != nil { |
| 100 | return err |
| 101 | } |
| 102 | |
| 103 | projectModified := false |
| 104 | for _, variableSet := range opts.VariableSets.Value { |
| 105 | targetVariableSet := util.SliceFilter(libraryVariableSets, func(item *variables.LibraryVariableSet) bool { return strings.EqualFold(variableSet, item.Name) }) |
| 106 | if util.Empty(targetVariableSet) { |
| 107 | return fmt.Errorf("cannot find library variable set '%s'", variableSet) |
| 108 | } |
| 109 | |
| 110 | if len(targetVariableSet) > 1 { |
| 111 | return fmt.Errorf("'%s' matched more than one library variable set", variableSet) |
| 112 | } |
| 113 | |
| 114 | if util.SliceContainsAny(project.IncludedLibraryVariableSets, func(item string) bool { return item == targetVariableSet[0].ID }) { |
| 115 | fmt.Fprint(opts.Out, output.Yellowf("'%s' is already included, skipping\n", targetVariableSet[0].Name)) |
| 116 | } else { |
| 117 | project.IncludedLibraryVariableSets = append(project.IncludedLibraryVariableSets, targetVariableSet[0].ID) |
| 118 | projectModified = true |
| 119 | fmt.Fprint(opts.Out, output.Cyanf("Including '%s' library variable set\n", targetVariableSet[0].Name)) |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | if projectModified { |
| 124 | _, err = opts.Client.Projects.Update(project) |
| 125 | if err != nil { |
| 126 | return err |
| 127 | } |
| 128 | |
| 129 | fmt.Fprintf(opts.Out, "Successfully updated included library variable sets\n") |
| 130 | } |
| 131 | |
| 132 | if !opts.NoPrompt { |
| 133 | autoCmd := flag.GenerateAutomationCmd(opts.CmdPath, opts.GetSpaceNameOrEmpty(), opts.Project, opts.VariableSets) |
| 134 | fmt.Fprintf(opts.Out, "\nAutomation Command: %s\n", autoCmd) |
| 135 | } |
| 136 | |
| 137 | return nil |
| 138 | } |
| 139 | |
| 140 | func PromptMissing(opts *IncludeOptions) error { |
| 141 | var project *projects.Project |
no test coverage detected