fix(cli): add spec-required --data-dir, --config-path, and -v global options to main_callback #11122

Merged
hurui200320 merged 1 commits from fix/cli-missing-global-options-data-dir-config-path-verbosity into master 2026-05-12 01:05:11 +00:00

1 Commits

Author SHA1 Message Date
hurui200320 01a7d6ffa2 fix(cli): add spec-required --data-dir, --config-path, and -v global options to main_callback
CI / benchmark-publish (pull_request) Has been skipped
CI / helm (pull_request) Successful in 42s
CI / push-validation (pull_request) Successful in 41s
CI / build (pull_request) Successful in 1m0s
CI / typecheck (pull_request) Successful in 1m36s
CI / benchmark-regression (pull_request) Failing after 1m33s
CI / lint (pull_request) Successful in 51s
CI / quality (pull_request) Successful in 58s
CI / security (pull_request) Successful in 1m41s
CI / integration_tests (pull_request) Successful in 4m13s
CI / unit_tests (pull_request) Successful in 4m20s
CI / e2e_tests (pull_request) Successful in 4m41s
CI / docker (pull_request) Successful in 2m42s
CI / coverage (pull_request) Successful in 11m9s
CI / status-check (pull_request) Successful in 4s
Implements ADR-021 §Global CLI Flags and ADR-024 §Resolution Chain.
All three global options were missing from main_callback(), causing any
invocation with these flags to crash with 'No such option'.

Changes:
- src/cleveragents/cli/main.py
  * Add _VERBOSITY_LOG_LEVELS tuple mapping verbose count to log levels
    (0=CRITICAL/silent, 1=ERROR, 2=WARNING, 3=INFO, 4=DEBUG, 5+=DEBUG)
  * Add --data-dir PATH option: validates path is a directory if it exists,
    sets CLEVERAGENTS_DATA_DIR env var, resets Settings singleton
  * Add --config-path PATH option: validates file exists and is a file,
    sets CLEVERAGENTS_CONFIG_PATH env var for ConfigService to pick up
  * Add -v (count=True) option: wires verbose count to configure_structlog
  * Store all three values in ctx.obj for subcommand access
  * Update _print_basic_help() to include the three new global options so
    'cleveragents --help' (fast path) also lists them
  * In the catch-all Exception handler, print the original exception
    type+message directly to err_console so actionable details remain
    visible even when log level is CRITICAL (e.g. 'No such option')

- src/cleveragents/application/services/config_service.py
  * ConfigService.__init__ now checks CLEVERAGENTS_CONFIG_PATH env var
    when no explicit config_path is passed, completing the resolution
    chain for --config-path CLI override

Tests (all passing):
- features/cli_global_options.feature (21 Behave scenarios)
- features/steps/cli_global_options_steps.py
- robot/cli_global_options.robot (8 Robot Framework integration tests)
- robot/helper_cli_global_options.py

Quality gates: lint ✓  typecheck ✓  unit_tests ✓  integration_tests ✓
Coverage: 96.52% (threshold 96.5% ✓)

ISSUES CLOSED: #6785
2026-05-11 14:06:38 +00:00