-
Notifications
You must be signed in to change notification settings - Fork 27
/
init.go
59 lines (45 loc) · 1.09 KB
/
init.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
package command
import (
"fmt"
"os"
"github.com/codegangsta/cli"
"github.com/hashicorp/errwrap"
"github.com/timeglass/glass/vcs"
)
type Init struct {
*command
}
func NewInit() *Init {
return &Init{newCommand()}
}
func (c *Init) Name() string {
return "init"
}
func (c *Init) Description() string {
return fmt.Sprintf("Install hooks for the current repository, if hooks already exists they are truncated and rewritten.")
}
func (c *Init) Usage() string {
return "Install Timeglass for the current repository"
}
func (c *Init) Flags() []cli.Flag {
return []cli.Flag{}
}
func (c *Init) Action() func(ctx *cli.Context) {
return c.command.Action(c.Run)
}
func (c *Init) Run(ctx *cli.Context) error {
dir, err := os.Getwd()
if err != nil {
return errwrap.Wrapf("Failed to fetch current working dir: {{err}}", err)
}
vc, err := vcs.GetVCS(dir)
if err != nil {
return errwrap.Wrapf("Failed to setup VCS: {{err}}", err)
}
err = vc.Hook()
if err != nil {
return errwrap.Wrapf("Failed to write hooks: {{err}}", err)
}
fmt.Println("Timeglass: hooks written")
return NewPull().Run(ctx)
}