mirror of
https://github.com/rjNemo/pomodoro
synced 2026-06-12 10:16:39 +00:00
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:
parent
bebe08e0ab
commit
85f1d3106f
1 changed files with 20 additions and 10 deletions
30
main.go
30
main.go
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -18,15 +19,16 @@ const (
|
||||||
|
|
||||||
var helpStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#626262")).Render
|
var helpStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#626262")).Render
|
||||||
|
|
||||||
type model struct {
|
type (
|
||||||
name string
|
model struct {
|
||||||
totalTime time.Duration
|
name string
|
||||||
elapsedTime time.Duration
|
totalTime time.Duration
|
||||||
done bool
|
elapsedTime time.Duration
|
||||||
progress progress.Model
|
progress progress.Model
|
||||||
}
|
}
|
||||||
|
|
||||||
type TickMsg time.Time
|
TickMsg time.Time
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if err := run(); err != nil {
|
if err := run(); err != nil {
|
||||||
|
|
@ -35,7 +37,16 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func run() error {
|
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 {
|
if _, err := p.Run(); err != nil {
|
||||||
return fmt.Errorf("could not start the timer app %w", err)
|
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
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// View implements tea.Model.
|
|
||||||
func (m model) View() string {
|
func (m model) View() string {
|
||||||
pad := strings.Repeat(" ", padding)
|
pad := strings.Repeat(" ", padding)
|
||||||
return "\n" +
|
return "\n" +
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue