forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handle_app_path_override.go
56 lines (43 loc) · 1.36 KB
/
handle_app_path_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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package v7pushaction
import (
"os"
"path/filepath"
"code.cloudfoundry.org/cli/command/translatableerror"
"code.cloudfoundry.org/cli/util/manifestparser"
)
// Overrides the path if path is given. Changes empty paths to pwd. Validates paths
func HandleAppPathOverride(manifest manifestparser.Manifest, overrides FlagOverrides) (manifestparser.Manifest, error) {
if overrides.ProvidedAppPath != "" {
if manifest.ContainsMultipleApps() {
return manifest, translatableerror.CommandLineArgsWithMultipleAppsError{}
}
app := manifest.GetFirstApp()
if app.Docker != nil {
return manifest, translatableerror.ArgumentManifestMismatchError{
Arg: "--path, -p",
ManifestProperty: "docker",
}
}
app.Path = overrides.ProvidedAppPath
}
for i := range manifest.Applications {
if manifest.Applications[i].Path == "" {
continue
}
var finalPath = manifest.Applications[i].Path
if !filepath.IsAbs(finalPath) && overrides.ProvidedAppPath == "" {
finalPath = filepath.Join(filepath.Dir(manifest.PathToManifest), finalPath)
}
finalPathNoLinks, err := filepath.EvalSymlinks(finalPath)
if err != nil {
if os.IsNotExist(err) {
return manifest, manifestparser.InvalidManifestApplicationPathError{
Path: finalPath,
}
}
return manifest, err
}
manifest.Applications[i].Path = finalPathNoLinks
}
return manifest, nil
}