(composeFilePaths []string, commandName string, optionVerbose bool, commandVersion string)
| 214 | } |
| 215 | |
| 216 | func SetCommandVersion(composeFilePaths []string, commandName string, optionVerbose bool, commandVersion string) { |
| 217 | rawProject, err := getRawProject(composeFilePaths) |
| 218 | if err != nil { |
| 219 | panic(err) |
| 220 | } |
| 221 | |
| 222 | rawService, err := rawProject.GetService(commandName) |
| 223 | |
| 224 | var versionVariableExpected = strings.ReplaceAll(strings.ToUpper(commandName), "-", "_") + "_VERSION" |
| 225 | var variablesUsed []string |
| 226 | for _, variable := range ExtractVariables(rawService) { |
| 227 | variablesUsed = append(variablesUsed, variable) |
| 228 | } |
| 229 | |
| 230 | if len(variablesUsed) == 0 { |
| 231 | fmt.Printf("Error: Version selection for %s is currently not supported.\n", commandName) |
| 232 | os.Exit(1) |
| 233 | } |
| 234 | |
| 235 | var versionVariablesUsed []string |
| 236 | for _, variable := range variablesUsed { |
| 237 | if strings.HasSuffix(variable, "_VERSION") { |
| 238 | versionVariablesUsed = append(versionVariablesUsed, variable) |
| 239 | } |
| 240 | } |
| 241 | versionKey := versionVariableExpected |
| 242 | |
| 243 | if !util.Contains(variablesUsed, versionVariableExpected) { |
| 244 | if len(versionVariablesUsed) == 1 { |
| 245 | fmt.Printf("Error: To specify the version of %s, please set %s.\n", |
| 246 | commandName, |
| 247 | versionVariablesUsed[0], |
| 248 | ) |
| 249 | os.Exit(1) |
| 250 | } else if len(versionVariablesUsed) > 1 { |
| 251 | fmt.Printf("Error: To specify the version of %s, please set one of:\n", commandName) |
| 252 | for _, versionVariable := range versionVariablesUsed { |
| 253 | fmt.Println(" " + versionVariable) |
| 254 | } |
| 255 | os.Exit(1) |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | if optionVerbose { |
| 260 | fmt.Printf("Setting %s to %s...\n", versionKey, commandVersion) |
| 261 | } |
| 262 | err = os.Setenv(versionKey, commandVersion) |
| 263 | if err != nil { |
| 264 | panic(err) |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | func LoadEnvFiles(hostCwd string, optionVerbose bool) error { |
| 269 | var envFiles []string |
nothing calls this directly
no test coverage detected