Skip to content

fix(cmd): stop travel subcommands clobbering persistent viper keys#33

Merged
omarshahine merged 1 commit intosteipete:mainfrom
omarshahine:fix/travel-viper-flag-collisions
Apr 16, 2026
Merged

fix(cmd): stop travel subcommands clobbering persistent viper keys#33
omarshahine merged 1 commit intosteipete:mainfrom
omarshahine:fix/travel-viper-flag-collisions

Conversation

@omarshahine
Copy link
Copy Markdown
Collaborator

Summary

`internal/cmd/travel.go` bound global viper keys to subcommand-local flags. Because `viper.BindPFlag` replaces prior bindings, several persistent flags were silently shadowed.

Visible symptoms

  1. `--timezone` ignored by metrics/sleep/schedule. The root persistent `--timezone` flag (bound in `root.go`) was re-bound in travel's `init()` to `travelCreateTripCmd`'s trip-body timezone flag — which defaults to `""`. A user running `eightctl metrics trends --timezone America/Los_Angeles` would get an empty tz. The recent tz-resolver then fell back to the system zone (or UTC with a warning when zoneinfo is unresolvable).

  2. `--trip`/`--plan` values leaking across travel subcommands. `trip`, `plan`, `name`, and `date` were each bound multiple times inside travel's `init()`, so only the last binding was live — making several travel subcommands unable to read their own flags.

Fix

Travel-subcommand-specific flags are now read via `cmd.Flags().GetString(...)` from the actual command being run, not through a colliding global viper key. The root persistent flags (`--timezone`, `--email`, `--password`, etc.) are untouched.

The trip-body timezone flag is renamed to `--trip-timezone` so it cannot visually collide with the persistent `--timezone` flag again.

Test plan

  • `eightctl metrics trends --timezone America/Los_Angeles --from … --to …` now sends `tz=America/Los_Angeles` (verified against live API; no UTC warning)
  • `go test ./...` passes
  • `go vet ./...` clean
  • `travel create-trip --trip-timezone …` still populates the trip body (sending the tz through the new flag name)

Scope

Narrowly the travel init(). No behavior change to any non-travel command other than the CLI flag values now actually reaching them.

🤖 Generated with Claude Code

travel.go's init() bound global viper keys (timezone, trip, plan, name,
date) to subcommand-local flags. Since viper.BindPFlag replaces prior
bindings, this had two effects:

- The root --timezone persistent flag was shadowed by
  travelCreateTripCmd's trip-body timezone flag (which defaults to "").
  Callers of `metrics trends --timezone ...`, `sleep day --timezone ...`,
  etc. got an empty tz and the client fell back to the system zone (or
  UTC with a warning on hosts without resolvable zoneinfo). The
  --timezone value passed on the CLI never reached the API.

- The trip/plan/name/date keys were each bound multiple times, so
  `travel plans --trip X` read from whichever flag was bound last.

Switch every travel-subcommand-specific flag to cmd.Flags().GetString(),
keeping viper only for genuinely global fields (email/password/user_id/
client_id/client_secret/output). Rename the trip-body timezone flag to
--trip-timezone so it cannot visually collide with the persistent
--timezone flag in the future.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@omarshahine omarshahine merged commit e032bc3 into steipete:main Apr 16, 2026
1 check passed
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