-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp_push.go
74 lines (68 loc) · 1.5 KB
/
app_push.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"fmt"
"github.com/igm/cf"
"log"
"os"
"path/filepath"
)
func init() {
register(&Command{
group: "Application",
name: "app.push",
help: "Push application (directory or file archive)",
params: []Param{
Param{name: "name", desc: "Application name"},
Param{name: "space", desc: "Space name"},
Param{name: "org", desc: "Organization name"},
Param{name: "path", desc: "Application path, or path to a archive file to upload (zip, war,...)", defval: "."},
},
handle: app_push,
})
}
func app_push() {
target, err := c.SelectedTarget()
if err != nil {
log.Fatal(err)
}
// Get Application ID
app, err := target.AppFind(params["name"], params["space"], params["org"])
if err != nil {
log.Fatal(err)
}
path := params["path"]
file, err := os.Open(path)
if err != nil {
log.Fatal(err)
}
defer file.Close()
stat, err := file.Stat()
if err != nil {
log.Fatal(err)
}
if stat.IsDir() {
var archetypes []*cf.Archetype
filepath.Walk(path, func(p string, info os.FileInfo, err error) error {
if !info.IsDir() {
file, err := os.Open(p)
if err != nil {
return err
}
fmt.Println("Adding file:", p)
norm, _ := filepath.Rel(path, p)
archetypes = append(archetypes, &cf.Archetype{
Name: norm,
Reader: file,
})
}
return nil
})
err = target.AppPush(app.Guid, archetypes)
if err != nil {
log.Fatal(err)
}
} else {
fmt.Println("Pushing file:", stat.Name())
err = target.AppPushArchive(app.Guid, file)
}
}