Skip to content

contrib: Autogenerate bitcoin-cli bash completion file from getopenrpcinfo - #35814

Open
carloantinarella wants to merge 2 commits into
bitcoin:masterfrom
carloantinarella:test-autogenerate-bash-completion-from-openrpc
Open

contrib: Autogenerate bitcoin-cli bash completion file from getopenrpcinfo#35814
carloantinarella wants to merge 2 commits into
bitcoin:masterfrom
carloantinarella:test-autogenerate-bash-completion-from-openrpc

Conversation

@carloantinarella

Copy link
Copy Markdown
Contributor

Fixes #17289

Current bitcoin-cli bash autocompletion file (contrib/completions/bash/bitcoin-cli.bash) needs to be manually updated in case RPC commands are created, modified or removed.
Attempts to tackle this issue have already been done in the past (#18606, #25243 and #30860), but none of them got to the point of getting merged.
The approach of this PR takes advantage of the new getopenrpcinfo command (#34683), parsing the OpenRPC resulting spec for autocompletion file generation. No further C++ code changes are needed, since the getopenrpcinfo output represents now a ready-made source of truth.

Autocompletion file explanation

Since it is now autogenerated, it can be more verbose than in the past, as maintainability is automatic.
Both bitcoin-cli options and RPC commands are handled explicitly. The RPC command arguments are handled both positionally and by name (previously they were handled only positionally):

  • _bitcoin_cli_positional() function autocompletes argument values as in the previous version. Since the getopenrpcinfo output does not provide information about enumerated values yet, they are lost in this PR (see for example the sighashtype argument of signrawtransactionwithkeys). Follow up PRs can refine that as soon as getopenrpcinfo provides these data.
  • _bitcoin_cli_named() function is invoked when bitcoin-cli -named argument is used. It is able to autocomplete RPC argument name followed by '=' and for the supported data (boolean values and file or dir paths) can also provide suggestions for argument values.

Test file tool_rpc_autocompletion.py

As suggested in #17289, the autocompletion file is autogenerated via functional test. The test invokes "bitcoin-cli -help" and "bitcoin-cli getopenrpcinfo" to collect all the data and builds completion file as a list of lines. Then, if "--overwrite" option is detected, the current autocompletion file is overwritten. Final check consists in the comparison of the actual autcompletion file content with the autogenerated one.

Possible issues and topics for discussion

The implementation excludes hidden command. Besides that, the autocompletion file most probably is containing a superset of available commands, as it does not take into account situations where bitcoind is compiled with some features disabled (e.g. wallet). Then user can meet the awkward situation in which a command is suggested but cannot work.

How to test

source contrib/completions/bash/bitcoin-cli.bash
cd build/bin/
./bitcoin-cli <TAB>
./bitcoin-cli -named <TAB>
./bitcoin-cli -named aban<TAB> <TAB>

Further testing and feedbacks are welcome.

Align bitcoin-cli.bash script to what is expected to be autogenerated
by test in tool_rpc_autocompletion.py.
The -named bitcoin-cli option is handled for supporting command
arguments autocompletion.
Add test RPCAutocompletionTest for checking bitcoin-cli
bash autocompletion script is always in synch with RPC data.
Bash script data is autogenerated parsing the output of
getopenrpcinfo rpc command.
Bash autocompletion script can be regenerated and overwritten
calling the test tool_rpc_autocompletion.py with "--overwrite"
argument.
@DrahtBot

DrahtBot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35814.

Reviews

See the guideline and AI policy for information on the review process.
A summary of reviews will appear here.

LLM Linter (✨ experimental)

Possible typos and grammar issues:

  • Param description regexpr to match file and/or directory path types -> Param description regex to match file and/or directory path types [“regexpr” is a misspelling/nonstandard abbreviation and may confuse readers]

2026-07-26 19:05:20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

contrib: Autogenerate bash completion

2 participants