feat: add possibility to track time in timewarrior as well
Some checks failed
Go CI Pipeline / ci (push) Has been cancelled

This commit is contained in:
Patryk Hegenberg 2025-10-10 09:07:15 +02:00
parent 127018b565
commit c0a83b5892
4 changed files with 44 additions and 15 deletions

19
cmd.go
View file

@ -12,6 +12,8 @@ import (
"github.com/spf13/cobra"
)
var withoutTimew bool
func (a *App) setupCommands() *cobra.Command {
rootCmd := &cobra.Command{
Use: "workctl",
@ -44,7 +46,7 @@ Use --background (-b) to keep tunnels running in the background without auto-con
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Println("Starting workday procedures...")
sshCon, err := a.connect()
sshCon, err := a.connect(withoutTimew)
if err != nil {
fmt.Printf("ERROR: Failed to start connections: %v\n", err)
return fmt.Errorf("connection setup failed: %w", err)
@ -71,7 +73,7 @@ Use --background (-b) to keep tunnels running in the background without auto-con
fmt.Println("\nINFO: Received interrupt signal. Shutting down background process...")
slog.Info("Received signal, cleanup via defer sshCon.Close() will run.")
if err := a.timeStore.StopTracking(); err != nil {
if err := a.timeStore.StopTracking(withoutTimew); err != nil {
slog.Warn(fmt.Sprintf("Failed to stop time tracking: %v", err))
} else {
slog.Info("Time tracking stopped.")
@ -84,7 +86,7 @@ Use --background (-b) to keep tunnels running in the background without auto-con
fmt.Println("Workstation SSH session finished.")
slog.Info("Foreground session ended, cleanup via defer sshCon.Close() will run.")
if err := a.timeStore.StopTracking(); err != nil {
if err := a.timeStore.StopTracking(withoutTimew); err != nil {
slog.Warn(fmt.Sprintf("Failed to stop time tracking: %v", err))
} else {
slog.Info("Time tracking stopped.")
@ -96,18 +98,19 @@ Use --background (-b) to keep tunnels running in the background without auto-con
}
cmd.Flags().BoolVarP(&a.flags.StartInBackground, "background", "b", false, "Run tunnels in the background instead of connecting immediately")
cmd.Flags().BoolVarP(&withoutTimew, "timew", "t", false, "Set this flag if you dont want to use Timewarrior Timestorage as well")
return cmd
}
func (a *App) stopCommand() *cobra.Command {
return &cobra.Command{
cmd := &cobra.Command{
Use: "stop",
Short: "Stop work: Stop time tracking, kill tunnels",
Long: "Stops the current time tracking entry and attempts to kill active SSH tunnels.",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Stopping workday procedures...")
if err := a.timeStore.StopTracking(); err != nil {
if err := a.timeStore.StopTracking(withoutTimew); err != nil {
slog.Error(fmt.Sprintf("Failed to stop time tracking: %v", err))
} else {
fmt.Println("Time tracking stopped.")
@ -122,6 +125,8 @@ func (a *App) stopCommand() *cobra.Command {
fmt.Println("Workday stop procedures finished.")
},
}
cmd.Flags().BoolVarP(&withoutTimew, "timew", "t", false, "Set this flag if you dont want to use Timewarrior Timestorage as well")
return cmd
}
func (a *App) trackCommand() *cobra.Command {
@ -159,7 +164,7 @@ This also stops any currently running timer.`,
default:
fmt.Printf("Attempting to start tracking interval '%s'...\n", tag)
if err := a.timeStore.StartTracking(tag); err != nil {
if err := a.timeStore.StartTracking(tag, withoutTimew); err != nil {
slog.Error(fmt.Sprintf("Failed to start tracking '%s': %v", tag, err))
return fmt.Errorf("could not start tracking '%s': %w", tag, err)
}
@ -173,7 +178,7 @@ This also stops any currently running timer.`,
Short: "Start tracking 'break'",
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Println("Starting break...")
if err := a.timeStore.StartTracking(TagBreak); err != nil {
if err := a.timeStore.StartTracking(TagBreak, withoutTimew); err != nil {
slog.Error(fmt.Sprintf("Failed to start break tracking: %v", err))
return fmt.Errorf("could not start break: %w", err)
}