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()