forked from openshift/geard
-
Notifications
You must be signed in to change notification settings - Fork 1
/
usage.go
54 lines (47 loc) · 1.25 KB
/
usage.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
package sti
import (
"log"
"net/url"
"os"
"path/filepath"
)
// Usage processes a build request by starting the container and executing
// the assemble script with a "-h" argument to print usage information
// for the script.
func Usage(req *STIRequest) error {
h, err := newHandler(req)
if err != nil {
return err
}
h.request.workingDir, err = createWorkingDirectory()
if err != nil {
return err
}
if h.request.PreserveWorkingDir {
log.Printf("Temporary directory '%s' will be saved, not deleted\n", h.request.workingDir)
} else {
defer removeDirectory(h.request.workingDir, h.request.Verbose)
}
dirs := []string{"scripts", "defaultScripts"}
for _, v := range dirs {
err := os.Mkdir(filepath.Join(h.request.workingDir, v), 0700)
if err != nil {
return err
}
}
if req.ScriptsUrl != "" {
url, _ := url.Parse(req.ScriptsUrl + "/" + "assemble")
downloadFile(url, h.request.workingDir+"/scripts/assemble", h.request.Verbose)
}
defaultUrl, err := h.getDefaultUrl()
if err != nil {
return err
}
if defaultUrl != "" {
url, _ := url.Parse(defaultUrl + "/" + "assemble")
downloadFile(url, h.request.workingDir+"/defaultScripts/assemble", h.request.Verbose)
}
h.request.usage = true
_, _, err = h.buildInternal()
return err
}