forked from flynn/flynn
/
app.go
54 lines (42 loc) · 1.03 KB
/
app.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 main
import (
"log"
"os/exec"
"github.com/flynn/flynn/Godeps/_workspace/src/github.com/flynn/go-docopt"
"github.com/flynn/flynn/controller/client"
ct "github.com/flynn/flynn/controller/types"
)
func init() {
register("create", runCreate, `
usage: flynn create [<name>]
Create an application in Flynn.
`)
register("apps", runApps, `
usage: flynn apps
List flynn apps.
`)
}
func runCreate(args *docopt.Args, client *controller.Client) error {
app := &ct.App{}
app.Name = args.String["<name>"]
if err := client.CreateApp(app); err != nil {
return err
}
exec.Command("git", "remote", "remove", "flynn").Run()
exec.Command("git", "remote", "add", "flynn", gitURLPre(serverConf.GitHost)+app.Name+gitURLSuf).Run()
log.Printf("Created %s", app.Name)
return nil
}
func runApps(args *docopt.Args, client *controller.Client) error {
apps, err := client.AppList()
if err != nil {
return err
}
w := tabWriter()
defer w.Flush()
listRec(w, "ID", "NAME")
for _, a := range apps {
listRec(w, a.ID, a.Name)
}
return nil
}