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 <noreply@anthropic.com>
This commit is contained in:
2026-04-16 19:19:12 +08:00
parent f06a1a34f1
commit 680bd3d33c
2 changed files with 25 additions and 2 deletions

View File

@@ -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"}

View File

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