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

pull carloantinarella wants to merge 2 commits into bitcoin:master from carloantinarella:test-autogenerate-bash-completion-from-openrpc changing 3 files +1574 −68
  1. carloantinarella commented at 7:04 PM on July 26, 2026: 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.

  2. contrib: update bash autocompletion script for bitcoin-cli
    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.
    f8b5832337
  3. test: test bitcoin-cli bash autocompletion is synched
    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.
    280c0bff04
  4. DrahtBot added the label Scripts and tools on Jul 26, 2026
  5. DrahtBot commented at 7:05 PM on July 26, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

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

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

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

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

    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]

    <sup>2026-07-26 19:05:20</sup>


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-07-31 20:50 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me