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.
This commit is contained in:
Ruidy 2025-05-18 23:46:11 +02:00
parent bebe08e0ab
commit 85f1d3106f
No known key found for this signature in database
GPG key ID: E00F51288CB857CC

30
main.go
View file

@ -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" +