Skip to content

M1.5: Add viper-based configuration #5

Description

@bjcorder

Labels: type:feature, area:cli, priority:high,
status:blocked, milestone:M1, phase:1

Summary

Integrate viper for configuration sourced from CLI flags, environment
variables, and a YAML config file, in that precedence order.

Acceptance criteria

  • internal/config/config.go defines a Config struct with:
    • DBPath string (default ~/.forkguard/state.db,
      env FORKGUARD_DB_PATH)
    • CacheDir string (default ~/.forkguard/cache,
      env FORKGUARD_CACHE_DIR)
    • GitHubToken string (default empty, env GITHUB_TOKEN)
    • LogFormat string (default json, env FORKGUARD_LOG_FORMAT)
    • LogLevel string (default info, env FORKGUARD_LOG_LEVEL)
  • Load(cmd *cobra.Command) (*Config, error) populates the config from
    flags, env vars, and a YAML file (in that precedence)
  • Default config file location is ~/.forkguard/config.yaml
  • Tilde expansion works correctly on all supported platforms
  • Tests cover all three precedence sources

Implementation notes

Use github.com/spf13/viper v1.18+. Bind viper to the cobra root command
in internal/cli/root.go's PersistentPreRunE.

Dependencies

Depends on: #4

Verification

FORKGUARD_DB_PATH=/tmp/test.db ./forkguard --help
go test ./internal/config/...

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:cliCLI commands, argument parsing, output formattingpriority:highImportant for the current milestonetype:featureNew functionality

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions