-
Notifications
You must be signed in to change notification settings - Fork 32
Add hook environment variables and break duration #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
3230123
f223bac
0572a45
7d334d2
f92f6cd
da40e76
73a9d73
544f889
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,13 +26,25 @@ func breakCmd(cmd *cobra.Command, args []string) error { | |
| } | ||
| } | ||
|
|
||
| if err := hook.Run(client, "break"); err != nil { | ||
| if err := hook.Run(client, hook.Params{ | ||
| Name: "break", | ||
| Command: "break", | ||
| Args: getCommandArgs(cmd), | ||
| BreakDuration: d, | ||
| }); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if err := wait(d); err != nil { | ||
| return err | ||
| if shouldWait(cmd, true) { | ||
| if err := wait(d); err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| return hook.Run(client, "stop") | ||
| return hook.Run(client, hook.Params{ | ||
| Name: "stop", | ||
| Command: "break", | ||
| Args: getCommandArgs(cmd), | ||
| BreakDuration: d, | ||
| }) | ||
|
Comment on lines
+44
to
+49
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,12 +3,14 @@ package cmd | |
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "os" | ||
| "strconv" | ||
| "time" | ||
|
|
||
| "github.com/justincampbell/go-countdown" | ||
| "github.com/justincampbell/go-countdown/format" | ||
| "github.com/open-pomodoro/go-openpomodoro" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| // wait displays a countdown timer for the specified duration | ||
|
|
@@ -23,6 +25,15 @@ func wait(d time.Duration) error { | |
| return err | ||
| } | ||
|
|
||
| // shouldWait determines if we should wait based on the wait flag and command context | ||
| // For break commands, wait by default unless --no-wait is explicitly set | ||
| func shouldWait(cmd *cobra.Command, defaultWait bool) bool { | ||
| if cmd.Flags().Changed("wait") { | ||
| return waitFlag | ||
| } | ||
| return defaultWait | ||
| } | ||
|
|
||
| // parseDurationMinutes parses a duration string, defaulting to minutes if no unit is specified | ||
| func parseDurationMinutes(s string) (time.Duration, error) { | ||
| if _, err := strconv.Atoi(s); err == nil { | ||
|
|
@@ -47,3 +58,15 @@ func isPomodoroCompleted(p *openpomodoro.Pomodoro) bool { | |
| current, _ := client.Pomodoro() | ||
| return current.IsInactive() || !current.Matches(p) | ||
| } | ||
|
|
||
| // getCommandArgs extracts the command-specific arguments from os.Args | ||
| func getCommandArgs(cmd *cobra.Command) []string { | ||
| for i, arg := range os.Args { | ||
| if arg == cmd.Name() || (i > 0 && os.Args[i-1] == "pomodoro") { | ||
| if arg == cmd.Name() { | ||
| return os.Args[i+1:] | ||
| } | ||
| } | ||
| } | ||
| return cmd.Flags().Args() | ||
| } | ||
|
Comment on lines
+62
to
+72
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
PomodoroIDfield is missing from the hook.Params struct, unlike other commands that include it. This inconsistency means break hooks won't have access to the pomodoro ID environment variable, which could be useful for tracking which pomodoro the break is associated with.