forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handle_app_name_override.go
41 lines (33 loc) · 1.07 KB
/
handle_app_name_override.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package v7pushaction
import (
"code.cloudfoundry.org/cli/cf/errors"
"code.cloudfoundry.org/cli/command/translatableerror"
"code.cloudfoundry.org/cli/util/manifestparser"
)
func HandleAppNameOverride(manifest manifestparser.Manifest, overrides FlagOverrides) (manifestparser.Manifest, error) {
if manifest.ContainsMultipleApps() && manifest.HasAppWithNoName() {
return manifest, errors.New("Found an application with no name specified.")
}
if overrides.AppName != "" {
newApps := make([]manifestparser.Application, 1)
foundApp := false
for _, app := range manifest.Applications {
if app.Name == overrides.AppName {
newApps[0] = app
foundApp = true
break
}
}
if !foundApp {
if len(manifest.Applications) == 1 {
manifest.Applications[0].Name = overrides.AppName
return manifest, nil
}
return manifest, manifestparser.AppNotInManifestError{Name: overrides.AppName}
}
manifest.Applications = newApps
} else if manifest.HasAppWithNoName() {
return manifest, translatableerror.AppNameOrManifestRequiredError{}
}
return manifest, nil
}