Skip to content

Commit

Permalink
Amend command
Browse files Browse the repository at this point in the history
Modifies the current Pomodoro
  • Loading branch information
justincampbell committed Jun 4, 2018
1 parent 0ec52f6 commit 89e2d47
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ $ pomodoro start --duration 22m30s
# Provide a description and tags
$ pomodoro start "Blog post" -t writing,personal
25:00 🍅
Writing a blog post
Blog post
writing,personal
# Block until the Pomodoro finishes
Expand All @@ -48,6 +48,21 @@ $ pomodoro start --wait
24:99
```

### Amend the current Pomodoro

```
$ pomodoro start "Blog postt" --tags writing,personal
25:00 🍅
Blog postt
writing,personal
# Pass any options accepted by start. Only passed options will be changed.
$ pomodoro amend "Blog post"
24:30 🍅
Blog post
writing,personal
```

### Check the status of the current Pomodoro

```
Expand Down
64 changes: 64 additions & 0 deletions cmd/amend.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package cmd

import (
"fmt"
"strings"
"time"

"github.com/spf13/cobra"
)

func init() {
command := &cobra.Command{
Use: "amend",
Short: "Amend the last Pomodoro",
RunE: amendCmd,
}

command.Flags().DurationVarP(
&agoFlag, "ago", "a", 0,
"time ago this Pomodoro started")

command.Flags().IntVarP(
&durationFlag, "duration", "d",
0,
"duration for this Pomodoro")

command.Flags().StringArrayVarP(
&tagsFlag, "tags", "t", []string{},
"tags for this Pomodoro")

RootCmd.AddCommand(command)
}

func amendCmd(cmd *cobra.Command, args []string) error {
h, err := client.History()
if err != nil {
return err
}
p := h.Latest()
if p == nil {
return fmt.Errorf("No Pomodoros found")
}

description := strings.Join(args, " ")
if description != "" {
p.Description = description
}
if durationFlag != 0 {
p.Duration = time.Duration(durationFlag) * time.Minute
}
if agoFlag != 0 {
p.StartTime = time.Now().Add(-agoFlag)
}
if len(tagsFlag) != 0 {
p.Tags = tagsFlag
}

err = client.Start(p)
if err != nil {
return err
}

return statusCmd(cmd, args)
}

0 comments on commit 89e2d47

Please sign in to comment.