fix(cli): promote --format to global CLI callback option per spec
CI / lint (pull_request) Successful in 21s
CI / quality (pull_request) Successful in 34s
CI / typecheck (pull_request) Successful in 51s
CI / security (pull_request) Successful in 1m0s
CI / build (pull_request) Successful in 19s
CI / helm (pull_request) Successful in 24s
CI / unit_tests (pull_request) Failing after 7m5s
CI / docker (pull_request) Has been skipped
CI / e2e_tests (pull_request) Successful in 16m51s
CI / integration_tests (pull_request) Successful in 23m16s
CI / coverage (pull_request) Successful in 10m39s
CI / status-check (pull_request) Failing after 1s
CI / benchmark-publish (pull_request) Has been skipped
CI / benchmark-regression (pull_request) Successful in 56m46s
CI / lint (pull_request) Successful in 21s
CI / quality (pull_request) Successful in 34s
CI / typecheck (pull_request) Successful in 51s
CI / security (pull_request) Successful in 1m0s
CI / build (pull_request) Successful in 19s
CI / helm (pull_request) Successful in 24s
CI / unit_tests (pull_request) Failing after 7m5s
CI / docker (pull_request) Has been skipped
CI / e2e_tests (pull_request) Successful in 16m51s
CI / integration_tests (pull_request) Successful in 23m16s
CI / coverage (pull_request) Successful in 10m39s
CI / status-check (pull_request) Failing after 1s
CI / benchmark-publish (pull_request) Has been skipped
CI / benchmark-regression (pull_request) Successful in 56m46s
Add `fmt: OutputFormat` parameter to `main_callback()` in
`src/cleveragents/cli/main.py` and store the selected format in
`ctx.obj["format"]` so all subcommands can read it without needing
their own per-command `--format` flag.
Remove per-command `--format` / `fmt` parameters from `version()`,
`info()`, and `diagnostics()` commands. These commands now read the
format from `ctx.obj.get("format", OutputFormat.RICH.value)`.
The specification states: "The framework supports six distinct output
formats, selectable via the global `--format` flag." This change
aligns the implementation with the spec by making `--format` a global
option on the root `agents` command (via the Typer callback).
All six formats (json, yaml, plain, rich, table, color) are supported
via the global flag and the `-f` shorthand.
Add Behave BDD scenarios covering global `--format` flag propagation
to subcommands for all six formats. Update Robot Framework integration
tests to exercise the global `--format` flag. Update existing tests
that used per-command `--format` for version/info/diagnostics to use
the global flag instead.
ISSUES CLOSED: #2908
This commit is contained in:
@@ -133,11 +133,99 @@ def plan_status_plain() -> None:
|
||||
print("cli-formats-plan-status-plain-ok")
|
||||
|
||||
|
||||
def global_format_json_version() -> None:
|
||||
"""Test global --format json propagates to version command."""
|
||||
from cleveragents.cli.main import app as main_app
|
||||
|
||||
result = runner.invoke(main_app, ["--format", "json", "version"])
|
||||
assert result.exit_code == 0, f"exit={result.exit_code}: {result.output}"
|
||||
parsed = json.loads(result.output.strip())
|
||||
assert isinstance(parsed, dict)
|
||||
assert "version" in parsed
|
||||
print("cli-global-format-json-version-ok")
|
||||
|
||||
|
||||
def global_format_yaml_version() -> None:
|
||||
"""Test global --format yaml propagates to version command."""
|
||||
from cleveragents.cli.main import app as main_app
|
||||
|
||||
result = runner.invoke(main_app, ["--format", "yaml", "version"])
|
||||
assert result.exit_code == 0, f"exit={result.exit_code}: {result.output}"
|
||||
parsed = yaml.safe_load(result.output.strip())
|
||||
assert isinstance(parsed, dict)
|
||||
assert "version" in parsed
|
||||
print("cli-global-format-yaml-version-ok")
|
||||
|
||||
|
||||
def global_format_plain_version() -> None:
|
||||
"""Test global --format plain propagates to version command."""
|
||||
from cleveragents.cli.main import app as main_app
|
||||
|
||||
result = runner.invoke(main_app, ["--format", "plain", "version"])
|
||||
assert result.exit_code == 0, f"exit={result.exit_code}: {result.output}"
|
||||
assert "version:" in result.output
|
||||
print("cli-global-format-plain-version-ok")
|
||||
|
||||
|
||||
def global_format_json_info() -> None:
|
||||
"""Test global --format json propagates to info command."""
|
||||
from cleveragents.cli.main import app as main_app
|
||||
|
||||
result = runner.invoke(main_app, ["--format", "json", "info"])
|
||||
assert result.exit_code == 0, f"exit={result.exit_code}: {result.output}"
|
||||
parsed = json.loads(result.output.strip())
|
||||
assert isinstance(parsed, dict)
|
||||
print("cli-global-format-json-info-ok")
|
||||
|
||||
|
||||
def global_format_json_diagnostics() -> None:
|
||||
"""Test global --format json propagates to diagnostics command."""
|
||||
from cleveragents.cli.main import app as main_app
|
||||
|
||||
result = runner.invoke(main_app, ["--format", "json", "diagnostics"])
|
||||
assert result.exit_code == 0, f"exit={result.exit_code}: {result.output}"
|
||||
parsed = json.loads(result.output.strip())
|
||||
assert isinstance(parsed, dict)
|
||||
print("cli-global-format-json-diagnostics-ok")
|
||||
|
||||
|
||||
def global_format_shorthand() -> None:
|
||||
"""Test global -f json shorthand propagates to version command."""
|
||||
from cleveragents.cli.main import app as main_app
|
||||
|
||||
result = runner.invoke(main_app, ["-f", "json", "version"])
|
||||
assert result.exit_code == 0, f"exit={result.exit_code}: {result.output}"
|
||||
parsed = json.loads(result.output.strip())
|
||||
assert isinstance(parsed, dict)
|
||||
assert "version" in parsed
|
||||
print("cli-global-format-shorthand-ok")
|
||||
|
||||
|
||||
def global_format_all_six() -> None:
|
||||
"""Test all six output formats work via the global --format flag."""
|
||||
from cleveragents.cli.main import app as main_app
|
||||
|
||||
formats = ["json", "yaml", "plain", "rich", "table", "color"]
|
||||
for fmt in formats:
|
||||
result = runner.invoke(main_app, ["--format", fmt, "version"])
|
||||
assert result.exit_code == 0, (
|
||||
f"Format '{fmt}' failed: exit={result.exit_code}: {result.output}"
|
||||
)
|
||||
print("cli-global-format-all-six-ok")
|
||||
|
||||
|
||||
_COMMANDS = {
|
||||
"action-list-json": action_list_json,
|
||||
"action-show-yaml": action_show_yaml,
|
||||
"plan-list-json": plan_list_json,
|
||||
"plan-status-plain": plan_status_plain,
|
||||
"global-format-json-version": global_format_json_version,
|
||||
"global-format-yaml-version": global_format_yaml_version,
|
||||
"global-format-plain-version": global_format_plain_version,
|
||||
"global-format-json-info": global_format_json_info,
|
||||
"global-format-json-diagnostics": global_format_json_diagnostics,
|
||||
"global-format-shorthand": global_format_shorthand,
|
||||
"global-format-all-six": global_format_all_six,
|
||||
}
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user