{
 "number": 35814,
 "repo": "bitcoin/bitcoin",
 "url": "https://github.com/bitcoin/bitcoin/pull/35814",
 "title": "contrib: Autogenerate bitcoin-cli bash completion file from getopenrpcinfo",
 "author": "carloantinarella",
 "author_association": "CONTRIBUTOR",
 "created_at": "2026-07-26T19:04:59Z",
 "updated_at": "2026-07-26T19:05:21Z",
 "age_days": 52,
 "draft": false,
 "labels": [
  "Scripts and tools"
 ],
 "milestone": null,
 "base": "master",
 "head_sha": "280c0bff047cee19ceb563c2d45f871d12e11083",
 "head_ref": "test-autogenerate-bash-completion-from-openrpc",
 "head_repo": "carloantinarella/bitcoin",
 "head_history": [],
 "additions": 1574,
 "deletions": 68,
 "changed_files": 3,
 "commit_count": 2,
 "size_bucket": "XL",
 "mergeable_state": "blocked",
 "bot": {
  "drahtbot": {
   "present": true,
   "reviews": {},
   "conflicts": []
  }
 },
 "acks_parsed": {},
 "acks_tally": {
  "ack": 0,
  "stale_ack": 0,
  "concept_ack": 0,
  "approach_ack": 0,
  "nack": 0,
  "concept_nack": 0,
  "approach_nack": 0
 },
 "reviews": {
  "approved": 0,
  "changes_requested": 0,
  "distinct_reviewers": []
 },
 "signals": {
  "needs_rebase": false,
  "ci_failed": false,
  "mergeable_state": "blocked",
  "last_author_activity": "2026-07-26T13:26:04Z",
  "last_reviewer_activity": null,
  "last_reviewer": null,
  "author_silent_days": 53,
  "waiting_on_author_days": 0,
  "days_since_update": 52
 },
 "refs": {
  "mentioned": [
   17289,
   18606,
   25243,
   30860,
   34683
  ],
  "depends_on": [],
  "fixes": [
   17289
  ],
  "linked_issues": [
   {
    "number": 17289,
    "type": "issue",
    "state": "open",
    "merged": false,
    "merged_at": null,
    "title": "contrib: Autogenerate bash completion"
   }
  ],
  "references": [
   {
    "number": 17289,
    "type": "issue",
    "state": "open",
    "merged": false,
    "merged_at": null,
    "title": "contrib: Autogenerate bash completion"
   },
   {
    "number": 18606,
    "type": "pull",
    "state": "closed",
    "merged": false,
    "merged_at": null,
    "title": "test: checks that bitcoin-cli autocomplete is in sync"
   },
   {
    "number": 25243,
    "type": "pull",
    "state": "closed",
    "merged": false,
    "merged_at": null,
    "title": "test: autogenerate bash completion"
   },
   {
    "number": 30860,
    "type": "pull",
    "state": "closed",
    "merged": false,
    "merged_at": null,
    "title": "test: autogenerate bash completion"
   },
   {
    "number": 34683,
    "type": "pull",
    "state": "closed",
    "merged": true,
    "merged_at": "2026-07-23",
    "title": "rpc: support a formal description of our JSON-RPC interface"
   }
  ],
  "conflicts": []
 },
 "stack": {
  "shares_commits_with": [],
  "based_on": [],
  "base_for": []
 },
 "review_paths": [],
 "body": "Fixes #17289\n\nCurrent 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.\nAttempts 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.\nThe 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.\n\n### Autocompletion file explanation\n\nSince it is now autogenerated, it can be more verbose than in the past, as maintainability is automatic.\nBoth 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):\n- __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.\n- __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.\n\n### Test file tool_rpc_autocompletion.py\n\nAs 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.\n\n### Possible issues and topics for discussion\n\nThe 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.\n\n### How to test\n\n\tsource contrib/completions/bash/bitcoin-cli.bash\n\tcd build/bin/\n\t./bitcoin-cli <TAB>\n\t./bitcoin-cli -named <TAB>\n\t./bitcoin-cli -named aban<TAB> <TAB>\n\nFurther testing and feedbacks are welcome.",
 "commits": [
  {
   "sha": "f8b583233728021952629f8e1b551977b325f0cb",
   "date": "2026-07-26T13:26:04Z",
   "message": "contrib: update bash autocompletion script for bitcoin-cli\n\nAlign bitcoin-cli.bash script to what is expected to be autogenerated\nby test in tool_rpc_autocompletion.py.\nThe -named bitcoin-cli option is handled for supporting command\narguments autocompletion."
  },
  {
   "sha": "280c0bff047cee19ceb563c2d45f871d12e11083",
   "date": "2026-07-26T13:26:04Z",
   "message": "test: test bitcoin-cli bash autocompletion is synched\n\nAdd test RPCAutocompletionTest for checking bitcoin-cli\nbash autocompletion script is always in synch with RPC data.\nBash script data is autogenerated parsing the output of\ngetopenrpcinfo rpc command.\nBash autocompletion script can be regenerated and overwritten\ncalling the test tool_rpc_autocompletion.py with \"--overwrite\"\nargument."
  }
 ],
 "timeline": [],
 "labels_log": [
  {
   "t": "2026-07-26T19:05:03Z",
   "action": "labeled",
   "label": "Scripts and tools",
   "who": "DrahtBot"
  }
 ],
 "state_log": [],
 "text_chars": 3362,
 "text_tokens_estimate": 840,
 "changed_paths": [
  "contrib/completions/bash/bitcoin-cli.bash",
  "test/functional/test_runner.py",
  "test/functional/tool_rpc_autocompletion.py"
 ],
 "files": [
  {
   "path": "contrib/completions/bash/bitcoin-cli.bash",
   "add": 1095,
   "del": 68
  },
  {
   "path": "test/functional/test_runner.py",
   "add": 1,
   "del": 0
  },
  {
   "path": "test/functional/tool_rpc_autocompletion.py",
   "add": 478,
   "del": 0
  }
 ],
 "test_lines": 1642,
 "git": {
  "head": "280c0bff047cee19ceb563c2d45f871d12e11083",
  "head_matches_backup": true,
  "base": "e34b8d5a7dcd45e4faa3bb5fdeae64bf049037f6",
  "commits": [
   {
    "sha": "f8b5832337",
    "subject": "contrib: update bash autocompletion script for bitcoin-cli",
    "files": 1,
    "add": 1095,
    "del": 68
   },
   {
    "sha": "280c0bff04",
    "subject": "test: test bitcoin-cli bash autocompletion is synched",
    "files": 2,
    "add": 479,
    "del": 0
   }
  ],
  "patch_truncated": true
 },
 "input_hash": "52657f4db8e3d381",
 "extracted_at": "2026-09-17T16:15:31+00:00"
}