MCPcopy Create free account
hub / github.com/datastack-net/dockerized / SetCommandVersion

Function SetCommandVersion

pkg/dockerized.go:216–266  ·  view source on GitHub ↗
(composeFilePaths []string, commandName string, optionVerbose bool, commandVersion string)

Source from the content-addressed store, hash-verified

214}
215
216func 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
268func LoadEnvFiles(hostCwd string, optionVerbose bool) error {
269 var envFiles []string

Callers

nothing calls this directly

Calls 3

ContainsFunction · 0.92
getRawProjectFunction · 0.85
ExtractVariablesFunction · 0.85

Tested by

no test coverage detected