Skip to content

feat: bind CLI client flags to Viper config (env vars + config file) #33

@Anthony-Bible

Description

@Anthony-Bible

Summary

The CLI client commands (repos, search, jobs) read --api-url and --timeout directly from cobra flags, bypassing Viper entirely. This means:

  • CODECHUNK_CLIENT_API_URL and CODECHUNK_CLIENT_TIMEOUT env vars are never picked up by commands (only by client.LoadConfig(), which is never called from any command handler)
  • No config file support for client settings
  • Every invocation requires explicit flags or relies on hardcoded defaults

Proposed Fix

  1. internal/client/commands/root.go — add Viper setup in NewRootCmd:

    • Bind --api-url persistent flag → client.api_url
    • Bind --timeout persistent flag → client.timeout
    • Bind env vars CODECHUNK_CLIENT_API_URL and CODECHUNK_CLIENT_TIMEOUT
  2. internal/client/commands/repos.go — update createClientFromFlags to read through Viper (viper.GetString / viper.GetDuration) instead of raw cobra flag access

Priority order (flag wins, then env var, then default)

--api-url flag > CODECHUNK_CLIENT_API_URL > http://localhost:8080
--timeout flag > CODECHUNK_CLIENT_TIMEOUT > 30s

Affected commands

All client subcommands share createClientFromFlags, so this fix covers:

  • repos list, repos get, repos add, repos delete, repos jobs, repos query
  • search
  • jobs get
  • health

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions