-
Notifications
You must be signed in to change notification settings - Fork 27
/
pause.go
65 lines (51 loc) · 1.26 KB
/
pause.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
package command
import (
"fmt"
"os"
"github.com/codegangsta/cli"
"github.com/hashicorp/errwrap"
"github.com/timeglass/glass/model"
)
type Pause struct {
*command
}
func NewPause() *Pause {
return &Pause{newCommand()}
}
func (c *Pause) Name() string {
return "pause"
}
func (c *Pause) Description() string {
return fmt.Sprintf("Pauses the timer, running 'glass start' or editing a file in the repository resumes the timer")
}
func (c *Pause) Usage() string {
return "Manually Pause the timer, go get some coffee"
}
func (c *Pause) Flags() []cli.Flag {
return []cli.Flag{}
}
func (c *Pause) Action() func(ctx *cli.Context) {
return c.command.Action(c.Run)
}
func (c *Pause) Run(ctx *cli.Context) error {
dir, err := os.Getwd()
if err != nil {
return errwrap.Wrapf("Failed to fetch current working dir: {{err}}", err)
}
m := model.New(dir)
info, err := m.ReadDaemonInfo()
if err != nil {
return errwrap.Wrapf(fmt.Sprintf("Failed to get Daemon address: {{err}}"), err)
}
client := NewClient(info)
err = client.Call("timer.pause")
if err != nil {
if err == ErrDaemonDown {
return errwrap.Wrapf(fmt.Sprintf("No timer appears to be running for '%s': {{err}}", dir), err)
} else {
return err
}
}
fmt.Println("Timeglass: timer paused")
return nil
}