feat(tpagectl): establish configuration management #537

Merged
fuzzy merged 3 commits from feat/cli-config into main 2026-08-05 06:19:48 +00:00
Owner

What

Adds the configuration system for the tpagectl CLI client, covering config struct definition, file lookup, environment variables, flag overrides, and the --config flag.

  • New internal/tpagectl/config package with a Config{Server: {URL, Token}} struct and a viper-based Load mirroring the daemon's pattern.
  • Config resolution precedence: defaults → .tpagectl.{yaml,json} file (., $XDG_CONFIG_HOME/tpagectl, /etc/tpagectl) → TPAGECTL_* environment variables → command-line flags.
  • Root command gains --config, --server, and --token flags; a Before hook loads config and applies flag overrides only when explicitly set, stashing the result in context for future subcommands.

Why

Phase 1 roadmap task #155. The CLI needs a config layer before HTTP client and command work (Phases 2+) can consume server URL and auth token.

Testing

  • Unit tests: config defaults, YAML/JSON loading, env override, env without file, auto-lookup, explicit missing file error
  • Unit tests: flag override precedence, env fallback, --config file and missing-file error
  • go test -race ./... passes
  • golangci-lint run clean
  • pre-commit hooks pass (gofmt, go mod tidy, go test)

Breaking Changes

None.

Notes

Reuses the existing github.com/spf13/viper dependency — no new modules. Env is handled in config.Load via viper, not at the flag level, so IsSet stays true only for explicit CLI flags.

Closes #150
Closes #151
Closes #152
Closes #153
Closes #154
Closes #155

## What Adds the configuration system for the tpagectl CLI client, covering config struct definition, file lookup, environment variables, flag overrides, and the `--config` flag. - New `internal/tpagectl/config` package with a `Config{Server: {URL, Token}}` struct and a viper-based `Load` mirroring the daemon's pattern. - Config resolution precedence: defaults → `.tpagectl.{yaml,json}` file (`.`, `$XDG_CONFIG_HOME/tpagectl`, `/etc/tpagectl`) → `TPAGECTL_*` environment variables → command-line flags. - Root command gains `--config`, `--server`, and `--token` flags; a `Before` hook loads config and applies flag overrides only when explicitly set, stashing the result in context for future subcommands. ## Why Phase 1 roadmap task #155. The CLI needs a config layer before HTTP client and command work (Phases 2+) can consume server URL and auth token. ## Testing - [x] Unit tests: config defaults, YAML/JSON loading, env override, env without file, auto-lookup, explicit missing file error - [x] Unit tests: flag override precedence, env fallback, `--config` file and missing-file error - [x] `go test -race ./...` passes - [x] `golangci-lint run` clean - [x] pre-commit hooks pass (gofmt, go mod tidy, go test) ## Breaking Changes None. ## Notes Reuses the existing `github.com/spf13/viper` dependency — no new modules. Env is handled in `config.Load` via viper, not at the flag level, so `IsSet` stays true only for explicit CLI flags. Closes #150 Closes #151 Closes #152 Closes #153 Closes #154 Closes #155
Add the tpagectl client configuration package. Resolves config in
precedence order: defaults, a .tpagectl.yaml or .tpagectl.json config
file, then TPAGECTL_* environment variables. Mirrors the daemon's
viper pattern with a CLI-specific prefix and file names.
Add --config, --server, and --token flags to the root command. A Before
hook loads the configuration and applies explicit flag overrides on top
of file and environment values, stashing the result in the context for
later subcommands.
docs(roadmap): mark configuration management complete
All checks were successful
Test and Release / lint (pull_request) Successful in 7m53s
Test and Release / test (pull_request) Successful in 8m5s
a451ca370c
Record completion of the tpagectl configuration system: client config
struct, .tpagectl.{yaml,json} lookup, TPAGECTL_* environment variables,
flag overrides, and the --config flag.

closes #150
closes #151
closes #152
closes #153
closes #154
closes #155
fuzzy scheduled this pull request to auto merge when all checks succeed 2026-08-05 06:05:57 +00:00
the.auditor left a comment

Summary

Configuration system for tpagectl. Verified: go test -race ./... passes (including new cmd/tpagectl and internal/tpagectl/config packages) and golangci-lint run ./... is clean. Pattern mirrors the daemon's internal/config closely. Closes #150-155.

No blocking issues.

Suggestions (filed as issues)

  1. cmd/tpagectl/main.go:79configFromContext returns nil without an error signal; future subcommands risk nil dereference. Filed as #538
  2. cmd/tpagectl/main.go:55--token flag exposes the API token via argv (ps/shell history); TPAGECTL_SERVER_TOKEN env is the safer path. Filed as #539
  3. internal/tpagectl/config/config.go:60SetConfigName(".tpagectl") auto-discovers all viper extensions, not just documented yaml/json; extension order is nondeterministic when multiple files exist. Filed as #540
  4. cmd/tpagectl/main_test.go – precedence chain tested for defaults/file/env/flag>env but not flag>file. Filed as #541

Praise

  • Clean mirror of the daemon config pattern — consistent conventions, good error wrapping
  • Meaningful test coverage across the full precedence chain
  • No real secrets in testdata; fake tokens throughout
## Summary Configuration system for tpagectl. Verified: `go test -race ./...` passes (including new `cmd/tpagectl` and `internal/tpagectl/config` packages) and `golangci-lint run ./...` is clean. Pattern mirrors the daemon's `internal/config` closely. Closes #150-155. No blocking issues. ## Suggestions (filed as issues) 1. `cmd/tpagectl/main.go:79` – `configFromContext` returns nil without an error signal; future subcommands risk nil dereference. Filed as #538 2. `cmd/tpagectl/main.go:55` – `--token` flag exposes the API token via argv (`ps`/shell history); `TPAGECTL_SERVER_TOKEN` env is the safer path. Filed as #539 3. `internal/tpagectl/config/config.go:60` – `SetConfigName(".tpagectl")` auto-discovers all viper extensions, not just documented yaml/json; extension order is nondeterministic when multiple files exist. Filed as #540 4. `cmd/tpagectl/main_test.go` – precedence chain tested for defaults/file/env/flag>env but not flag>file. Filed as #541 ## Praise - Clean mirror of the daemon config pattern — consistent conventions, good error wrapping - Meaningful test coverage across the full precedence chain - No real secrets in testdata; fake tokens throughout
fuzzy merged commit a451ca370c into main 2026-08-05 06:19:48 +00:00
fuzzy deleted branch feat/cli-config 2026-08-05 06:19:49 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
thwap/thwap-pagesd!537
No description provided.