Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/DylanDevelops/tmpo/internal/export"
"github.com/DylanDevelops/tmpo/internal/storage"
"github.com/DylanDevelops/tmpo/internal/ui"
"github.com/spf13/cobra"
)

Expand All @@ -24,10 +25,11 @@ var exportCmd = &cobra.Command{
Short: "Export time entries",
Long: `Export time tracking data to different formats.`,
Run: func(cmd *cobra.Command, args []string) {
ui.NewlineAbove()

db, err := storage.Initialize()
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)

ui.PrintError(ui.EmojiError, fmt.Sprintf("%v", err))
os.Exit(1)
}

Expand Down Expand Up @@ -56,14 +58,13 @@ var exportCmd = &cobra.Command{
}

if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)

ui.PrintError(ui.EmojiError, fmt.Sprintf("%v", err))
os.Exit(1)
}

if len(entries) == 0 {
fmt.Println("No entries to export.")

ui.PrintWarning(ui.EmojiWarning, "No entries to export.")
ui.NewlineBelow()
os.Exit(0)
}

Expand Down Expand Up @@ -91,18 +92,18 @@ var exportCmd = &cobra.Command{
case "json":
err = export.ToJson(entries, filename)
default:
fmt.Fprintf(os.Stderr, "Error: Unknown format '%s'. Use 'csv' or 'json'\n", exportFormat)

ui.PrintError(ui.EmojiError, fmt.Sprintf("Unknown format '%s'. Use 'csv' or 'json'", exportFormat))
os.Exit(1)
}

if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)

ui.PrintError(ui.EmojiError, fmt.Sprintf("%v", err))
os.Exit(1)
}

fmt.Printf("[tmpo] Exported %d entries to %s\n", len(entries), filename)
ui.PrintSuccess(ui.EmojiExport, fmt.Sprintf("Exported %d entries to %s", len(entries), filename))

ui.NewlineBelow()
},
}

Expand Down
30 changes: 19 additions & 11 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/DylanDevelops/tmpo/internal/config"
"github.com/DylanDevelops/tmpo/internal/project"
"github.com/DylanDevelops/tmpo/internal/ui"
"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
)
Expand All @@ -22,8 +23,10 @@ var initCmd = &cobra.Command{
Short: "Initialize a .tmporc config file",
Long: `Create a .tmporc configuration file in the current directory using an interactive form.`,
Run: func(cmd *cobra.Command, args []string) {
ui.NewlineAbove()

if _, err := os.Stat(".tmporc"); err == nil {
fmt.Println("Error: .tmporc already exists in this directory")
ui.PrintError(ui.EmojiError, ".tmporc already exists in this directory")
os.Exit(1)
}

Expand All @@ -41,7 +44,8 @@ var initCmd = &cobra.Command{
description = ""
} else {
// Interactive form
fmt.Println("\n[tmpo] Initialize Project Configuration")
ui.PrintSuccess(ui.EmojiInit, "Initialize Project Configuration")
fmt.Println()

// Project Name prompt
namePrompt := promptui.Prompt{
Expand All @@ -51,7 +55,7 @@ var initCmd = &cobra.Command{

nameInput, err := namePrompt.Run()
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
ui.PrintError(ui.EmojiError, fmt.Sprintf("%v", err))
os.Exit(1)
}

Expand All @@ -68,15 +72,15 @@ var initCmd = &cobra.Command{

rateInput, err := ratePrompt.Run()
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
ui.PrintError(ui.EmojiError, fmt.Sprintf("%v", err))
os.Exit(1)
}

rateInput = strings.TrimSpace(rateInput)
if rateInput != "" {
hourlyRate, err = strconv.ParseFloat(rateInput, 64)
if err != nil {
fmt.Fprintf(os.Stderr, "Error parsing hourly rate: %v\n", err)
ui.PrintError(ui.EmojiError, fmt.Sprintf("parsing hourly rate: %v", err))
os.Exit(1)
}
}
Expand All @@ -88,7 +92,7 @@ var initCmd = &cobra.Command{

descInput, err := descPrompt.Run()
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
ui.PrintError(ui.EmojiError, fmt.Sprintf("%v", err))
os.Exit(1)
}

Expand All @@ -98,19 +102,23 @@ var initCmd = &cobra.Command{
// Create the .tmporc file
err := config.CreateWithTemplate(name, hourlyRate, description)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
ui.PrintError(ui.EmojiError, fmt.Sprintf("%v", err))
os.Exit(1)
}

fmt.Printf("\n[tmpo] Created .tmporc for project '%s'\n", name)
fmt.Println()
ui.PrintSuccess(ui.EmojiSuccess, fmt.Sprintf("Created .tmporc for project '%s'", name))
if hourlyRate > 0 {
fmt.Printf(" Hourly Rate: $%.2f\n", hourlyRate)
ui.PrintInfo(4, "Hourly Rate", fmt.Sprintf("$%.2f", hourlyRate))
}
if description != "" {
fmt.Printf(" Description: %s\n", description)
ui.PrintInfo(4, "Description", description)
}

fmt.Println("\nYou can edit .tmporc to customize your project settings.")
fmt.Println()
ui.PrintMuted(0, "You can edit .tmporc to customize your project settings.")

ui.NewlineBelow()
},
}

Expand Down
35 changes: 21 additions & 14 deletions cmd/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/DylanDevelops/tmpo/internal/storage"
"github.com/DylanDevelops/tmpo/internal/ui"
"github.com/spf13/cobra"
)

Expand All @@ -21,10 +22,12 @@ var logCmd = &cobra.Command{
Short: "View time tracking history",
Long: `Display past time tracking entries with optional filtering.`,
Run: func(cmd *cobra.Command, args []string) {
ui.NewlineAbove()

db, err := storage.Initialize()

if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
ui.PrintError(ui.EmojiError, fmt.Sprintf("%v", err))
os.Exit(1)
}

Expand All @@ -42,7 +45,7 @@ var logCmd = &cobra.Command{
if weekday == 0 {
weekday = 7 // sunday
}

start := now.AddDate(0, 0, -weekday+1).Truncate(24 * time.Hour)
end := start.AddDate(0, 0, 7)
entries, err = db.GetEntriesByDateRange(start, end)
Expand All @@ -53,17 +56,18 @@ var logCmd = &cobra.Command{
}

if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
ui.PrintError(ui.EmojiError, fmt.Sprintf("%v", err))
os.Exit(1)
}

if len(entries) == 0 {
fmt.Println("No time entries found.")

ui.PrintWarning(ui.EmojiWarning, "No time entries found.")
ui.NewlineBelow()
return
}

fmt.Printf("\n[tmpo] Time Entries (%d total)\n\n", len(entries))
ui.PrintSuccess(ui.EmojiLog, fmt.Sprintf("Time Entries (%d total)", len(entries)))
fmt.Println()

var totalDuration time.Duration
currentDate := ""
Expand All @@ -75,28 +79,31 @@ var logCmd = &cobra.Command{
fmt.Println()
}

fmt.Printf("─── %s ───\n", entryDate)
fmt.Println(ui.Muted(fmt.Sprintf("─── %s ───", entryDate)))
currentDate = entryDate
}

duration := entry.Duration()
totalDuration += duration

timeRange := entry.StartTime.Format("03:04 PM")
timeRange := entry.StartTime.Format("03:04 PM") + " - "
if entry.EndTime != nil {
timeRange += " - " + entry.EndTime.Format("03:04 PM")
timeRange += entry.EndTime.Format("03:04 PM") + " "
} else {
timeRange += " - (running)"
timeRange += ui.Warning("(running)") + " "
}

fmt.Printf(" %s %-20s %s\n", timeRange, entry.ProjectName, formatDuration(duration))
fmt.Printf(" %s %-20s %s\n", timeRange, entry.ProjectName, ui.FormatDuration(duration))
if entry.Description != "" {
fmt.Printf(" └─ %s\n", entry.Description)
fmt.Printf(" %s %s\n", ui.Muted("└─"), entry.Description)
}
}

fmt.Printf("\n─────────────────────────────────────────\n")
fmt.Printf("Total Time: %s\n", formatDuration(totalDuration))
fmt.Println()
ui.PrintSeparator()
fmt.Printf("%s %s\n", ui.Info("Total Time:"), ui.FormatDuration(totalDuration))

ui.NewlineBelow()
},
}

Expand Down
Loading
Loading