Skip to content

Commit

Permalink
no longer show nasty error messages on commit whem daemon is not runn…
Browse files Browse the repository at this point in the history
…ing, fixes #5 [spent 22m10s]
  • Loading branch information
advdv committed May 22, 2015
1 parent fd5bef7 commit 2d56765
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
12 changes: 11 additions & 1 deletion command/lap.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ func (c *Lap) Usage() string {
}

func (c *Lap) Flags() []cli.Flag {
return []cli.Flag{}
return []cli.Flag{
cli.BoolFlag{
Name: "from-hook",
Usage: "Indicate it is called from a git, now expects refs on stdin",
},
}
}

func (c *Lap) Action() func(ctx *cli.Context) {
Expand All @@ -56,6 +61,11 @@ func (c *Lap) Run(ctx *cli.Context) error {
t, err := client.Lap()
if err != nil {
if err == ErrDaemonDown {
//if were calling this from a hook, supress errors
if ctx.Bool("from-hook") {
return nil
}

return errwrap.Wrapf(fmt.Sprintf("No timer appears to be running for '%s': {{err}}", dir), err)
} else {
return err
Expand Down
2 changes: 1 addition & 1 deletion command/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (c *Pull) Name() string {
}

func (c *Pull) Description() string {
return fmt.Sprintf("PUll the Timeglass notes branch from the remote repository. Provide the remote's name as the first argument, if no argument is provided it tries to pull from to the VCS default remote")
return fmt.Sprintf("Pull the Timeglass notes branch from the remote repository. Provide the remote's name as the first argument, if no argument is provided it tries to pull from to the VCS default remote")
}

func (c *Pull) Usage() string {
Expand Down
5 changes: 5 additions & 0 deletions command/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ func (c *Status) Run(ctx *cli.Context) error {
status, err := client.GetStatus()
if err != nil {
if err == ErrDaemonDown {
//if called from hook, don't interrupt
if ctx.Bool("time-only") {
return nil
}

return errwrap.Wrapf(fmt.Sprintf("No timer appears to be running for '%s': {{err}}", dir), err)
} else {
return err
Expand Down
2 changes: 1 addition & 1 deletion command/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (c *command) Action(fn func(c *cli.Context) error) func(ctx *cli.Context) {
return func(ctx *cli.Context) {
err := fn(ctx)
if err != nil {
c.Fatalf("[Error]: %s", err)
c.Fatalf("[Timeglass Error]: %s", err)
return
}
}
Expand Down
2 changes: 1 addition & 1 deletion vcs/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ esac

var PostCommitTmpl = template.Must(template.New("name").Parse(`#!/bin/sh
#always reset after commit
glass lap
glass lap --from-hook
`))

var PrePushTmpl = template.Must(template.New("name").Parse(`#!/bin/sh
Expand Down

0 comments on commit 2d56765

Please sign in to comment.