contrib: Autogenerate bitcoin-cli bash completion file from getopenrpcinfo - #35814
Open
carloantinarella wants to merge 2 commits into
Open
Conversation
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.
Contributor
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35814. ReviewsSee the guideline and AI policy for information on the review process. LLM Linter (✨ experimental)Possible typos and grammar issues:
2026-07-26 19:05:20 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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):
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
Further testing and feedbacks are welcome.