Skip to content

Cli flags and wiring#5

Merged
TyostoKarry merged 3 commits into
mainfrom
cli-flags-and-wiring
Mar 9, 2026
Merged

Cli flags and wiring#5
TyostoKarry merged 3 commits into
mainfrom
cli-flags-and-wiring

Conversation

@TyostoKarry

Copy link
Copy Markdown
Owner

Introduce the CLI entry point for sleepycli, allowing users to interact with the application via the terminal. Includes robust argument parsing, validation of sleep cycle parameters, and the execution logic for calculating sleep/wake times.

CLI Infrastructure

  • Dependency: Added github.com/spf13/pflag to enable shorthand flags (e.g., -w, -s) which are not supported by the standard library.
  • Entry Point: Implemented main.go to handle flag parsing and signal processing.
  • Execution Modes: Added runWakeMode, runSleepMode, and runWindowMode to execute specific business logic based on user flags.
  • Build: Added sleepycli to .gitignore.

Validation Refactoring

  • Refactoring: Converted the monolithic Validate() function into focused helper functions (validateWindow, validateTimeFlags, etc.) for better maintainability.
  • Normalization: Added NormalizeHour helper to handle single-digit hour inputs (e.g., "7:00") gracefully.
  • New Logic: Implemented specific validation for the --from/--to window mode, ensuring exclusive use and correct format checking.
  • Rewrote validation tests

Refactors the monolithic Validate() into focused private helpers and
adds support for validating --from/--to window flags.

Changes:
- Add FromTime/ToTime fields to Config
- Add validateModes() to reject mixed flag groups (--from/--to with
--wake/--sleep)
- Add validateWindow() for --from/--to pair validation
- Extract validateTimeFlags(), validateBuffer(), validateCycles() as
focused helpers
- Add normalizeHour() to accept single-digit hours (e.g. 7:00)
- Improve error messages to reference flag names (--wake, --sleep, etc.)

Tests:
- Add TestValidateWindow covering valid, missing, invalid, and mixed
cases
- Add TestValidateTimeFlagsMutualExclusion for both-set and neither-set
- Add edge cases: zero buffer, equal min/max cycles, short hour formats
- Fix test name "valid wake time format" -> "valid wake time short hour"
Adds pflag as a dependency to support shorthand CLI flags (e.g. -w, -s).

The standard library flag package does not support single-character
shorthands, so pflag is used as a drop-in replacement.
- Add CLI argument parsing using `spf13/pflag` to handle user input.
- Implement `runWakeMode`, `runSleepMode`, and `runWindowMode` functions
to process input and display cycle calculations.
- Expose `NormalizeHour` in the `validate` package to ensure consistent
input formatting across the app.
- Update `main.go` entry point to validate flags and route execution to
the selected mode.
- Add `sleepycli` to `.gitignore` to exclude build artifacts.
@TyostoKarry TyostoKarry self-assigned this Mar 9, 2026
@TyostoKarry TyostoKarry merged commit 5ced564 into main Mar 9, 2026
2 checks passed
@TyostoKarry TyostoKarry deleted the cli-flags-and-wiring branch March 9, 2026 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant