From 680bd3d33c8017f3c94e95ab251d9a32553cc070 Mon Sep 17 00:00:00 2001 From: Tacit Lab Date: Thu, 16 Apr 2026 19:19:12 +0800 Subject: [PATCH] fix: allow -a/--agent flag after subcommands - Preprocess argv to reorder agent flag before subcommand parsing. - Enables usage like `coinhunter account overview -s -f -a`. - Bump version to 2.0.6. Co-Authored-By: Claude Opus 4.6 --- pyproject.toml | 2 +- src/coinhunter/cli.py | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ab83957..9908790 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "coinhunter" -version = "2.0.5" +version = "2.0.6" description = "Binance-first trading CLI for balances, market data, opportunity scanning, and execution." readme = "README.md" license = {text = "MIT"} diff --git a/src/coinhunter/cli.py b/src/coinhunter/cli.py index cc6c3b4..ee155c3 100644 --- a/src/coinhunter/cli.py +++ b/src/coinhunter/cli.py @@ -135,9 +135,32 @@ def build_parser() -> argparse.ArgumentParser: return parser +def _reorder_agent_flag(argv: list[str]) -> list[str]: + """Move -a/--agent from after subcommands to before them so argparse can parse it.""" + agent_flags = {"-a", "--agent"} + subcommand_idx: int | None = None + for i, arg in enumerate(argv): + if not arg.startswith("-"): + subcommand_idx = i + break + if subcommand_idx is None: + return argv + new_argv: list[str] = [] + agent_present = False + for i, arg in enumerate(argv): + if i >= subcommand_idx and arg in agent_flags: + agent_present = True + continue + new_argv.append(arg) + if agent_present: + new_argv.insert(subcommand_idx, "--agent") + return new_argv + + def main(argv: list[str] | None = None) -> int: parser = build_parser() - args = parser.parse_args(argv) + raw_argv = argv if argv is not None else sys.argv[1:] + args = parser.parse_args(_reorder_agent_flag(raw_argv)) try: if not args.command: parser.print_help()