Skip to content

refactor: extract shared CLI helpers to reduce duplication in cmd/gaze #199

Description

@yvonnedevlinrh

Context

cmd/gaze/main.go contains several repeated patterns that could be extracted into shared helpers. These patterns were introduced incrementally as new subcommands were added and have accumulated 3-7 copies each. Extracting them reduces maintenance burden and lowers cyclomatic complexity of the parent functions.

Related: codebase audit from #166 triage

Patterns to Extract

Pattern Occurrences Description Proposed Helper
Format validation 5 switch format { case "json": ... case "text": ... default: error } repeated across runAnalyze, runClassify, runQuality, runCrap, runReport validateFormat(format string, allowed ...string) error
Module root discovery 7 findModuleRoot + os.Chdir pattern repeated in every runXxx function resolveModuleDir(args []string) (string, error)
JSON capture 2 captureJSON duplicated between main.go and aireport/runner.go Move to shared location or deduplicate
Main package auto-detect 4 loader.IsMainPkg check + includeUnexported = true pattern autoDetectUnexported(pkgPath string) bool
Config best-effort load 2 loadGazeConfigBestEffort duplicated between goprovider and aireport Already consolidated to config.LoadFromDir — verify no remaining copies

Acceptance Criteria

  • Each duplicated pattern has a single source of truth
  • All runXxx functions in cmd/gaze/main.go use the shared helpers
  • No behavioral changes — all existing tests pass without modification
  • go test -race -count=1 -short ./... passes
  • golangci-lint run reports zero issues

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

Status
In Progress 📋

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions