From 85f1d3106f94fe3924f6b6f857d504632748cbd5 Mon Sep 17 00:00:00 2001 From: Ruidy Date: Sun, 18 May 2025 23:46:11 +0200 Subject: [PATCH] feat: add CLI flags for timer name and duration Introduce command-line flags to customize the timer's name and duration. The `-name` flag sets the timer's label, and the `-duration` flag accepts a Go duration string (e.g., "25m", "1h"). This enhances flexibility for users to configure their Pomodoro sessions directly from the command line. --- main.go | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index 91ee85b..7f6855b 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "flag" "fmt" "log" "strings" @@ -18,15 +19,16 @@ const ( var helpStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#626262")).Render -type model struct { - name string - totalTime time.Duration - elapsedTime time.Duration - done bool - progress progress.Model -} +type ( + model struct { + name string + totalTime time.Duration + elapsedTime time.Duration + progress progress.Model + } -type TickMsg time.Time + TickMsg time.Time +) func main() { if err := run(); err != nil { @@ -35,7 +37,16 @@ func main() { } func run() error { - p := tea.NewProgram(initialModel("work", 25*time.Minute)) + name := flag.String("name", "Pomodoro", "Name of the timer") + durationString := flag.String("duration", "25m", "Duration of the timer") + flag.Parse() + + duration, err := time.ParseDuration(*durationString) + if err != nil { + return fmt.Errorf("could not parse duration %s: %w", *durationString, err) + } + + p := tea.NewProgram(initialModel(*name, duration)) if _, err := p.Run(); err != nil { return fmt.Errorf("could not start the timer app %w", err) } @@ -87,7 +98,6 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, nil } -// View implements tea.Model. func (m model) View() string { pad := strings.Repeat(" ", padding) return "\n" +