Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1#!/usr/bin/env python32# Copyright (c) 2015-present The Bitcoin Core developers3# Distributed under the MIT software license, see the accompanying4# file COPYING or http://www.opensource.org/licenses/mit-license.php.6'''7This checks if all command line args are documented.8Return value is 0 to indicate no error.9'''11from subprocess import check_output12import re14FOLDER_GREP = 'src'15FOLDER_TEST = 'src/test/'16REGEX_ARG = r'\b(?:GetArg|GetArgs|GetBoolArg|GetIntArg|GetPathArg|IsArgSet|get_net)\("(-[^"]+)"'17REGEX_DOC = r'AddArg\("(-[^"=]+?)(?:=|")'18CMD_ROOT_DIR = '$(git rev-parse --show-toplevel)/{}'.format(FOLDER_GREP)19CMD_GREP_ARGS = r"git grep --perl-regexp '{}' -- {} ':(exclude){}'".format(REGEX_ARG, CMD_ROOT_DIR, FOLDER_TEST)20CMD_GREP_WALLET_ARGS = r"git grep --function-context 'void WalletInit::AddWalletOptions' -- {} | grep AddArg".format(CMD_ROOT_DIR)21CMD_GREP_WALLET_HIDDEN_ARGS = r"git grep --function-context 'void DummyWalletInit::AddWalletOptions' -- {}".format(CMD_ROOT_DIR)22CMD_GREP_DOCS = r"git grep --perl-regexp '{}' {}".format(REGEX_DOC, CMD_ROOT_DIR)23# list unsupported, deprecated and duplicate args as they need no documentation24SET_DOC_OPTIONAL = set(['-h', '-?', '-dbcrashratio', '-forcecompactdb', '-ipcconnect', '-ipcfd'])27def lint_missing_argument_documentation():28used = check_output(CMD_GREP_ARGS, shell=True, text=True).strip()29docd = check_output(CMD_GREP_DOCS, shell=True, text=True).strip()31args_used = set(re.findall(re.compile(REGEX_ARG), used))32args_docd = set(re.findall(re.compile(REGEX_DOC), docd)).union(SET_DOC_OPTIONAL)33args_need_doc = args_used.difference(args_docd)34args_unknown = args_docd.difference(args_used)36print("Args used : {}".format(len(args_used)))37print("Args documented : {}".format(len(args_docd)))38print("Args undocumented: {}".format(len(args_need_doc)))39print(args_need_doc)40print("Args unknown : {}".format(len(args_unknown)))41print(args_unknown)43assert 0 == len(args_need_doc), "Please document the following arguments: {}".format(args_need_doc)46def lint_missing_hidden_wallet_args():47wallet_args = check_output(CMD_GREP_WALLET_ARGS, shell=True, text=True).strip()48wallet_hidden_args = check_output(CMD_GREP_WALLET_HIDDEN_ARGS, shell=True, text=True).strip()50wallet_args = set(re.findall(re.compile(REGEX_DOC), wallet_args))51wallet_hidden_args = set(re.findall(re.compile(r' "([^"=]+)'), wallet_hidden_args))53hidden_missing = wallet_args.difference(wallet_hidden_args)54if hidden_missing:55assert 0, "Please add {} to the hidden args in DummyWalletInit::AddWalletOptions".format(hidden_missing)58def main():59lint_missing_argument_documentation()60lint_missing_hidden_wallet_args()63if __name__ == "__main__":64main()
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.