This PR simplifies the argument parsing logic and resolves practical issues for bitcoin-cli and similar binaries (e.g. bitcoin-wallet) making their usage more consistent and predictable, enabling valid patterns such as mixing commands with wallet- or RPC-specific options—without relying on argument ordering quirks.
-
Previously,
ArgsManagerstopped interpreting options once a non-option argument was encountered (non-GNU parsing). For example:bitcoind -a -b param -cwould ignore
-cbecause it followed the non-option argumentparam. In some cases ‘-c’ is interpreted as an argument for ‘param’, producing unexpected behavior (eg empty arrays for listtransactions command). -
This PR changes the behavior so that options following non-option argument are recognized and processed (GNU parsing). This is needed for workflows for tools like CLI where command arguments may be followed by wallet- or RPC-specific options, e.g.:
bitcoin-cli -rpcwallet="" listtransactions -rpcwallet=mywallet bitcoin-cli getaddressinfo <address> -rpcwallet=mywallet -
(other binaries could also benefit from this change, e.g.
bitcoin-wallet)bitcoin-wallet create -wallet=newname -
Invalid options passed after non-options will be treated as RPC arguments that begin with a
-character (so no behavioural change againstmaster), e.g.:bitcoin-cli -regtest -datadir=/tmp/btc createwallet -mywallet { "name": "-mywallet" }
0./build_master/bin/bitcoin-cli -regtest -datadir=/tmp/btc getaddressinfo bcrt1qrnz5xlcwz5d85n3fag6v0vc4lryjc90jhqtpsh -rpcwallet=nonExistent
1error message:
2getaddressinfo "address"
3...
0./build/bin/bitcoin-cli -regtest -datadir=/tmp/btc getaddressinfo bcrt1qrnz5xlcwz5d85n3fag6v0vc4lryjc90jhqtpsh -rpcwallet=nonExistent
1error code: -18
2error message:
3Requested wallet does not exist or is not loaded
0./build_master/bin/bitcoin-cli -regtest -datadir=/tmp/btc listtransactions -rpcwallet=nonExistent
1[
2]
0./build/bin/bitcoin-cli -regtest -datadir=/tmp/btc listtransactions -rpcwallet=nonExistent
1error code: -18
2error message:
3Requested wallet does not exist or is not loaded
0./build_master/bin/bitcoin-cli -regtest -datadir=/tmp/btc listtransactions
1error code: -19
2error message:
3Multiple wallets are loaded. Please select which wallet to use by requesting the RPC through the /wallet/<walletname> URI path. Or for the CLI, specify the "-rpcwallet=<walletname>" option before the command (run "bitcoin-cli -h" for help or "bitcoin-cli listwallets" to see which wallets are currently loaded).
0./build_master/bin/bitcoin-cli -regtest -datadir=/tmp/btc listtransactions -rpcwallet=""
1error code: -19
2error message:
3Multiple wallets are loaded. Please select which wallet to use by requesting the RPC through the /wallet/<walletname> URI path. Or for the CLI, specify the "-rpcwallet=<walletname>" option before the command (run "bitcoin-cli -h" for help or "bitcoin-cli listwallets" to see which wallets are currently loaded).
0/build/bin/bitcoin-cli -regtest -datadir=/tmp/btc listtransactions -rpcwallet=""
1[
2 {
3 "address": "bcrt1q5pqkrlfrp9rvsg43sxxagrees7r7ul6uyskhs4",
4 "parent_descs": [
5 "wpkh([76a11ab0/84h/1h/0h]tpubDCDCuyC1Rtm1weZ5kfBYtdchcmqa2t8db7M68wsPHbWhUrYnzFTrHu7ufVVRydt3FdWQy8iNmKbZYbgpWWcEKPAj896x53UbS6i2xRD1qct/0/*)#kuff3m9t"
6 ],
7 "category": "immature",
8 "amount": 50.00000000,
9 "label": "",
10...
0./build_master/bin/bitcoin-wallet -regtest -datadir=/tmp/btc create
1Wallet name must be provided when creating a new wallet.
(-wallet option has to be passed before the create command in order to work)
0./build_master/bin/bitcoin-wallet -regtest -datadir=/tmp/btc create -wallet=newWalletName
1Error: Additional arguments provided (-wallet=newWalletName). Methods do not take arguments. Please refer to `-help`.
0./build/bin/bitcoin-wallet -regtest -datadir=/tmp/btc create -wallet=newWallet
1Topping up keypool...
2Wallet info
3===========
4Name: newWallet
5Format: sqlite
6Descriptors: yes
7Encrypted: no
8HD (hd seed available): yes
9Keypool Size: 8000
10Transactions: 0
11Address Book: 0
-Notes:
-
Backwards compatibility: This PR is backward compatible in the sense that it allows new valid invocations that were previously rejected (failed or somehow ignored). In
master, any valid option following a command is treated as a positional argument. This can lead to unexpected RPC errors or help messages due to mismatched argument types. With this PR, those cases are parsed as proper options when applicable. -
bitcoin-clicontinues to accept RPC arguments that begin with a-character as currently inmaster(checkcreatewalletexample in “What’s change in ArgsManager” section above). -
bitcoin-clicould distinguish between options that begin with single and double dashes, and treat options after the RPC method name that begin with double dashes as RPC named parameters (check example in 4th commit message body).