#35831 argsman, cli: Allow options after non-option arguments (GNU-style)
https://github.com/bitcoin/bitcoin/pull/35831 · · +285/-38 in 7 files, 3 commits · labels: none
Goal
- Allow CLI options to be placed after commands without being silently ignored or misparsed
- Prevents confusing errors or targeting the wrong wallet when passing options after an RPC command
This PR updates ArgsManager to parse options that appear after non-option arguments (subcommands and positional parameters) using GNU-style conventions. Unrecognized options following a command now produce errors instead of being silently swallowed into the command's positional arguments, and the '--' separator is supported to terminate option parsing. Additionally, bitcoin-cli and bitcoin-tx are updated to consume the pre-filtered arguments from ArgsManager.
Problem: In existing code, any argument following the first non-option argument was treated verbatim as a positional command argument. Consequently, trailing options such as -rpcwallet were silently ignored, potentially sending commands to the wrong wallet or triggering unexpected RPC errors when misspelled options were absorbed as positional values.
Category: RPC / REST / ZMQ (#22 of 52)
P3 · bug fix
- P3 because options like -rpcwallet placed after a command no longer fall back to default
- Eliminates silent wallet fallback and confusing parameter mismatch errors for CLI users
P3 because it fixes confusing CLI behavior where options like -rpcwallet were silently ignored when provided after an RPC command, avoiding accidental execution against unintended wallets.
Membership: Modifies bitcoin-cli command parsing and usage text.
Factors: security/stability 1, bug 2, performance 0, user value 2, leverage 0
Category: Tools and scripts (#12 of 22)
P3 · bug fix
- P3 because it brings consistent option handling after positional arguments to offline tools
- Improves usability for tools like bitcoin-tx and bitcoin-wallet when passing trailing options
P3 because it updates bitcoin-tx to consume pre-parsed commands from ArgsManager, preventing flags following transaction inputs from causing command-line errors.
Membership: Modifies bitcoin-tx argument handling and benefits bitcoin-wallet CLI syntax.
Factors: security/stability 0, bug 1, performance 0, user value 1, leverage 0
Category: Utilities (logging, arguments, libraries) (#9 of 66)
P3 · new feature
- P3 because it fixes parser behavior where trailing options were silently swallowed as values
- Unrecognized trailing options are now properly caught and validated across consumers
P3 because it introduces standard GNU-style option parsing to ArgsManager across all node tools, stopping silent ingestion of invalid options and supporting the standard '--' option terminator.
Membership: Changes ArgsManager::ParseParameters in src/common/args.cpp.
Factors: security/stability 1, bug 2, performance 0, user value 2, leverage 1
Reviewability: Ready
- Ready to review because the author addressed previous feedback on edge cases and CI passes
The author addressed all review points with corresponding tests and received an ACK on the head commit.
Author status: active, last pushed fixes addressing all review comments
Resolved concerns:
- w0xlt noted that '--' only worked after a command, not before it; resolved by extending '--' processing to the pre-command loop.
- w0xlt identified that Windows option parsing misclassified options like /datadir=C:/path as paths; resolved by restricting the embedded slash check to the option name.
- w0xlt pointed out that a lone '-' was rejected as an invalid option; resolved by checking length > 1.
- w0xlt and vicjuma noted that bitcoin-tx failed when trailing options like -json were used; resolved by reading from gArgs.GetCommand() rather than raw argv.
Agreement: Strong
- Strong support across the approach with edge cases tested and addressed
- Full support after suggesting edge-case fixes that the author incorporated (w0xlt)
- Verified tool consistency after concerns about bitcoin-tx behavior were resolved (vicjuma)
Strong: w0xlt reviewed in detail, supplied several test cases and fixes, and ACKed the latest push.
The PR has substantial engagement and an explicit ACK from w0xlt following resolution of multiple parser corner cases.
- w0xlt gave Concept ACK on 2026-07-29, Approach ACK on 2026-08-13, and final commit ACK on 2026-08-13.
Objections:
| Reviewer | Kind | Harm | Status | Blocking | Author replied | Quote |
|---|---|---|---|---|---|---|
| w0xlt | correctness | The '--' separator failed when specified before subcommands, e.g., in bitcoin-wallet. | resolved | no | yes | 2026-08-12: '--' is only recognized after the command, so using it before the first positional argument... incorrectly fails Settled: 2026-08-13: ACK 67a8e5bea2e30c66d7f4eb33e8b124943c5d705f |
| w0xlt | correctness | Windows slash options with path values (/datadir=C:/bitcoin) were mistaken for positional arguments. | resolved | no | yes | 2026-08-13: on Windows, a post-command option such as /datadir=C:/bitcoin is mistaken for a positional argument Settled: 2026-08-13: ACK 67a8e5bea2e30c66d7f4eb33e8b124943c5d705f |
Support:
- w0xlt: ACK on head commit after thorough review and verification of multiple edge cases.
Participants: w0xlt (support), vicjuma (neutral)
State derived from the lists: substantive support, no open objection (w0xlt)
Review verdicts (DrahtBot): 1
- ACK: w0xlt
Files
191 lines under test/bench/ci.
- src/test/argsman_tests.cpp +167/-6
- src/common/args.cpp +68/-10
- src/bitcoin-tx.cpp +17/-12
- doc/release-notes-35831.md +14/-0
- test/functional/interface_bitcoin_cli.py +10/-3
- src/bitcoin-cli.cpp +4/-7
- test/functional/data/util/bitcoin-util-test.json +5/-0
Card
This PR implements GNU-style command-line option parsing in ArgsManager, allowing options to be specified after subcommands and positional arguments. It prevents misplaced or misspelled options from being silently treated as positional parameters, fixes wallet routing errors with trailing -rpcwallet arguments, and adds '--' delimiter support. The changes directly benefit bitcoin-cli, bitcoin-wallet, and bitcoin-tx. All review feedback on edge cases has been addressed and the PR is ACKed by w0xlt.