Skip to content

refactor: extract common 'start pomodoro prompt' into reusable function #11

@LudoLoops

Description

@LudoLoops

Issue

The code "Start a Pomodoro? (Y/n):" is duplicated in:

  • cmd/new.go:82-88
  • cmd/start.go:38-46

Both have identical logic asking user to start a Pomodoro.

Solution

Create helper function in cmd/ or utils:

func promptAndStartPomodoro(reader *bufio.Reader, cfg config.Config) bool {
    fmt.Print("Start a Pomodoro? (Y/n): ")
    input, _ := reader.ReadString('\n')
    if trimmed := strings.ToLower(strings.TrimSpace(input)); trimmed == "y" || trimmed == "" {
        pomodoro.StartPomodoroCycle(cfg)
        return true
    }
    return false
}

Usage:

reader := bufio.NewReader(os.Stdin)
promptAndStartPomodoro(reader, cfg)

Benefits

  • Eliminates code duplication
  • Consistent behavior across commands
  • Easy to modify pomodoro prompting logic

Impact

🟢 Low - Maintenance improvement

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions