Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from timeglass/0.5
Version 0.5
- Loading branch information
Showing
18 changed files
with
547 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.4.0 | ||
0.5.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package command | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/codegangsta/cli" | ||
"github.com/hashicorp/errwrap" | ||
|
||
"github.com/timeglass/glass/vcs" | ||
) | ||
|
||
type Pull struct { | ||
*command | ||
} | ||
|
||
func NewPull() *Pull { | ||
return &Pull{newCommand()} | ||
} | ||
|
||
func (c *Pull) Name() string { | ||
return "pull" | ||
} | ||
|
||
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") | ||
} | ||
|
||
func (c *Pull) Usage() string { | ||
return "Pull time data from the remote repository" | ||
} | ||
|
||
func (c *Pull) Flags() []cli.Flag { | ||
return []cli.Flag{} | ||
} | ||
|
||
func (c *Pull) Action() func(ctx *cli.Context) { | ||
return c.command.Action(c.Run) | ||
} | ||
|
||
func (c *Pull) 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) | ||
} | ||
|
||
remote := ctx.Args().First() | ||
if remote == "" { | ||
remote = vc.DefaultRemote() | ||
} | ||
|
||
err = vc.Fetch(remote) | ||
if err != nil { | ||
if err == vcs.ErrNoRemoteTimeData { | ||
fmt.Printf("Timeglass: remote '%s' has no time data (yet), nothing to pull\n", remote) | ||
return nil | ||
} | ||
|
||
return errwrap.Wrapf("Failed to pull time data: {{err}}", err) | ||
} | ||
|
||
fmt.Println("Timeglass: time data fetched successfully") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package command | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
"github.com/codegangsta/cli" | ||
"github.com/hashicorp/errwrap" | ||
|
||
"github.com/timeglass/glass/vcs" | ||
) | ||
|
||
type Punch struct { | ||
*command | ||
} | ||
|
||
func NewPunch() *Punch { | ||
return &Punch{newCommand()} | ||
} | ||
|
||
func (c *Punch) Name() string { | ||
return "punch" | ||
} | ||
|
||
func (c *Punch) Description() string { | ||
return fmt.Sprintf("") | ||
} | ||
|
||
func (c *Punch) Usage() string { | ||
return "Manually register time spent on the last commit" | ||
} | ||
|
||
func (c *Punch) Flags() []cli.Flag { | ||
return []cli.Flag{} | ||
} | ||
|
||
func (c *Punch) Action() func(ctx *cli.Context) { | ||
return c.command.Action(c.Run) | ||
} | ||
|
||
func (c *Punch) Run(ctx *cli.Context) error { | ||
dir, err := os.Getwd() | ||
if err != nil { | ||
return errwrap.Wrapf("Failed to fetch current working dir: {{err}}", err) | ||
} | ||
|
||
if ctx.Args().First() == "" { | ||
return fmt.Errorf("Please provide the time you spent as the first argument") | ||
} | ||
|
||
t, err := time.ParseDuration(ctx.Args().First()) | ||
if err != nil { | ||
return errwrap.Wrapf(fmt.Sprintf("Failed to parse provided argument '%s' as a valid duration (e.g 1h2m10s): {{err}}", ctx.Args().First()), err) | ||
} | ||
|
||
//write the vcs | ||
vc, err := vcs.GetVCS(dir) | ||
if err != nil { | ||
return errwrap.Wrapf("Failed to setup VCS: {{err}}", err) | ||
} | ||
|
||
err = vc.Log(t) | ||
if err != nil { | ||
return errwrap.Wrapf("Failed to log time into VCS: {{err}}", err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package command | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
|
||
"github.com/codegangsta/cli" | ||
"github.com/hashicorp/errwrap" | ||
|
||
"github.com/timeglass/glass/model" | ||
"github.com/timeglass/glass/vcs" | ||
) | ||
|
||
type Push struct { | ||
*command | ||
} | ||
|
||
func NewPush() *Push { | ||
return &Push{newCommand()} | ||
} | ||
|
||
func (c *Push) Name() string { | ||
return "push" | ||
} | ||
|
||
func (c *Push) Description() string { | ||
return fmt.Sprintf("Pushes the Timeglass notes branch to the remote repository. Provide the remote's name as the first argument, if no argument is provided it tries to push to the VCS default remote") | ||
} | ||
|
||
func (c *Push) Usage() string { | ||
return "Push time data to the remote repository" | ||
} | ||
|
||
func (c *Push) Flags() []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 *Push) Action() func(ctx *cli.Context) { | ||
return c.command.Action(c.Run) | ||
} | ||
|
||
func (c *Push) 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) | ||
conf, err := m.ReadConfig() | ||
if err != nil { | ||
return errwrap.Wrapf(fmt.Sprintf("Failed to read configuration: {{err}}"), err) | ||
} | ||
|
||
//hooks require us require us to check the refs that are pushed over stdin | ||
//to prevent inifinte push loop | ||
refs := "" | ||
if ctx.Bool("from-hook") { | ||
bytes, err := ioutil.ReadAll(os.Stdin) | ||
if err != nil { | ||
return errwrap.Wrapf("Failed to read from stdin: {{err}}", err) | ||
} | ||
|
||
refs = string(bytes) | ||
//when `glass push` triggers the pre-push hook it will not | ||
//provide any refs on stdin | ||
//this probalby means means there is nothing left to push and | ||
//we return here to prevent recursive push | ||
if refs == "" { | ||
return nil | ||
} | ||
|
||
//configuration can explicitly request not to push time data automatically | ||
//on hook usage | ||
if !conf.AutoPush { | ||
return nil | ||
} | ||
} | ||
|
||
vc, err := vcs.GetVCS(dir) | ||
if err != nil { | ||
return errwrap.Wrapf("Failed to setup VCS: {{err}}", err) | ||
} | ||
|
||
remote := ctx.Args().First() | ||
if remote == "" { | ||
remote = vc.DefaultRemote() | ||
} | ||
|
||
err = vc.Push(remote, refs) | ||
if err != nil { | ||
if err == vcs.ErrNoLocalTimeData { | ||
fmt.Printf("Timeglass: local clone has no time data (yet), nothing to push to '%s'. Start a timer and commit changes to record local time data.\n", remote) | ||
return nil | ||
} | ||
|
||
return errwrap.Wrapf("Failed to push time data: {{err}}", err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.