mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:50:37 +00:00
argsman, cli: Allow options after non-option arguments (GNU-style) #35831
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!35831
Loading…
Reference in a new issue
No description provided.
Delete branch "argsman/gnu-parsing-options-after-commands"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Allow options to be specified after non-option arguments in
ParseParameters, matching GNU option parsing conventions (getopt_longstyle).Currently in
master, once the first non-dash argument was encountered, all subsequent arguments were collected verbatim intom_command. This meant-rpcwalletand similar options were silently ignored when placed after a command or its positional args. The same misspelled option before the command would be a clear error; after the command, it was silently treated as a positional argument — potentially triggering unintended RPC behaviour.With this change:
command_line_optionsexactly as if they appeared before the command.--separator stops option processing; all subsequent arguments are treated as positional regardless of leading dashes.bitcoin-cli'sCommandLineRPCis updated to derive its args vector fromgArgs.GetCommand()rather than re-scanning rawargv.bitcoin-walletbenefits automatically: options such as-walletplaced after a command are now parsed correctly instead of being rejected as unexpected positional arguments.Before and after: options after a command are now recognized...
-rpcwalletafter the command and its positional args:Before (
master) —-rpcwalletis silently ignored; request goes to the wrong wallet:After — correctly routes to the named wallet and fails with the expected error:
getaddressinfowith-rpcwalletappended:Before (
master) —-rpcwalletbecomes an extra positional arg;getaddressinfoerrors with its usage string:After — wallet is correctly selected:
Multi-wallet:
-rpcwalletno longer needs to come before the command:Before (
master):After:
— error message updated:
— command executed successfully:
Before and after: misspelled options and the
--separator...Misspelled option is now an error rather than a silent positional arg:
Before (
master) —-rpcwalllet(note triple-l) silently absorbed as thelabelpositional arg:After:
--separator: pass a dash-prefixed string as a positional RPC argument:Before and after:
bitcoin-walletcommands...-walletoption placed after the command:Before (
master) — option treated as an unexpected positional arg:After:
Backwards compatibility: command lines where a dash-prefixed argument follows a non-dash argument will now be parsed as an option (if recognized) or an error (if not). Previously such arguments were silently collected as positional args. The
--separator can be used to pass arguments that begin with a dash as positional args.The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
LLM Linter (✨ experimental)
Possible places where named args for integral literals may be used (e.g.
func(x, /*named_arg=*/0)in C++, andfunc(x, named_arg=0)in Python):self.nodes[0].cli('-generate', n5, 1000000, rpcwallet2).send_cli()intest/functional/interface_bitcoin_cli.py2026-08-13 04:47:45
🚧 At least one of the CI tasks failed.
Task
test ancestor commits: https://github.com/bitcoin/bitcoin/actions/runs/30377658579/job/90337348515LLM reason (✨ experimental): CI failed because the
argsman_testsCTest suite failed (non-zero exit status 8 from “Errors while running CTest”).Hints
Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the
affected test.
An intermittent issue.
Leave a comment here, if you need help tracking down a confusing failure.
-Updates:
rpc_psbt.py) — positional arguments after a command (e.g. base64 PSBTs) were being lowercased, corrupting their values.wallet_multiwallet.py) — paths starting with/after a command were being converted to-and parsed as options; fixed by only applying the Windows/→-conversion when there is no embedded slash (distinguishing/rpcwallet=foofrom/bad/./path).feature_pruning.py) — negative integers like-10after a command were incorrectly treated as options instead of positional arguments.#ifdef WIN32unit test covering Windows option syntax(/OPT=val,-OPTION) after a command, addressing a case raised in #33540.Concept ACK.
-Updates:
is_numbercheck: removed the opt_start variable, added acmd_key[1] != '-'guard so--10is now an error (consistent with pre-command behaviour). Intent is clearer: single dash + all digits => negative integer => positional arg.util_AddCommandfor a valid option specified after its command ({"x", "cmd2", "-opt1=foo"}), complementing the existing error case.bitcoin-walletbenefit, backwards compatibility note, reordered for clarity.WALLET_NOT_SPECIFIEDerror message reads "before or after the command".🐙 This pull request conflicts with the target branch and needs rebase.
:-)
This change produces a unified output, especially with the
-namedarg. Before the change, different RPC commands could result in different error messages:Before this change
Getting a new address
Listing transactions
After this change
Getting a new address
Listing transactions
I guess it may be necessary. I am a bit skeptical though cause probably it will have to be replicated across all the other targets too as opposed to just
bitcoin-cli. This will mean it should be possible to use this inbitcoin-txsuccessfully, etcThe help utility is already detailed for users who may be confused about the ordering
I will wait for other reviews on this to get a clear picture.
Thanks for your review @vicjuma.
bitcoin-walletalready benefits from this PR as it usesGetCommand()mainly, which would need to be added intobitcoin-tx, feature I've added in previous #33540 ate47c722324and will be added in a follow-up to this PR as other features from the same previous PR. The intention of this PR is to be simpler and more focused to the GNU-style parsing.Perhaps you should include the previous line that was the one added:
--is only recognized after the command, so using it before the first positional argument (for example,bitcoin-wallet -help -- create) incorrectly fails withInvalid parameter --.In GNU-style parsing,
--should end option processing wherever it appears.Suggested fix
In the current PR code, on Windows, a post-command option such as
/datadir=C:/bitcoinis mistaken for a positional argument because its value contains/.Suggested fix
A lone - after a command, such as in
bitcoin-cli echo -, is incorrectly treated as an option and rejected withInvalid parameter -.A single hyphen is a positional argument; an option must contain at least one character after it.
Suggested fix
In the current PR code, the parser correctly recognizes a trailing option like
-json, butbitcoin-txlater rereads the original arguments and mistakenly treats-jsonas a transaction-editing command, causing error:unknown command.The below fix makes
bitcoin-txuse the already-filtered arguments while keeping its special- stdinbehavior intact.Suggested fix
Approach ACK
I didn't want to include any change into
bitcoin-tx, as @ryanofsky suggested in previous #33540 but it this code is making the tool fail, I'll add the fix, thanks!-Updates:
--before command, release notes);/OPT=C:/bitcoinafter a command was mistakenly treated as positional because the embedded/in the value triggered the path check; now only the option name (before=) is checked;-after a command was misidentified as an option; now requires size > 1;cmd=valwas being normalized by the outer =-split);bitcoin-txCommandLineRawTxnow usesgArgs.GetCommand()instead of re-scanning rawargv, so GNU-style options after the transaction hex work correctly;--to also end option processing before the command (outer loop), not just after it.(CI failures are not related)
ACK
67a8e5bea2Base:
66776840beb558f7e84451c2c55457f0e06242f0Head:
67a8e5bea2e30c66d7f4eb33e8b124943c5d705fNo verified findings are available from this partial review.
Review coverage was incomplete. The archaeology review had incomplete evidence. The adversarial review had incomplete evidence. The adversarial_glm review did not complete.
Full review report