2017-12-12 20:47:24 +01:00
|
|
|
#!/usr/bin/env python3
|
2019-02-21 02:03:13 +01:00
|
|
|
# Copyright (c) 2015-2019 The Bitcoin Core developers
|
2016-01-04 02:06:04 +01:00
|
|
|
# Distributed under the MIT software license, see the accompanying
|
|
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
'''
|
|
|
|
This checks if all command line args are documented.
|
|
|
|
Return value is 0 to indicate no error.
|
|
|
|
|
|
|
|
Author: @MarcoFalke
|
|
|
|
'''
|
|
|
|
|
|
|
|
from subprocess import check_output
|
|
|
|
import re
|
|
|
|
|
|
|
|
FOLDER_GREP = 'src'
|
|
|
|
FOLDER_TEST = 'src/test/'
|
2019-02-02 02:00:02 +01:00
|
|
|
REGEX_ARG = r'(?:ForceSet|SoftSet|Get|Is)(?:Bool)?Args?(?:Set)?\("(-[^"]+)"'
|
|
|
|
REGEX_DOC = r'AddArg\("(-[^"=]+?)(?:=|")'
|
2019-04-28 16:33:22 +02:00
|
|
|
CMD_ROOT_DIR = '$(git rev-parse --show-toplevel)/{}'.format(FOLDER_GREP)
|
2018-03-28 19:57:17 +02:00
|
|
|
CMD_GREP_ARGS = r"git grep --perl-regexp '{}' -- {} ':(exclude){}'".format(REGEX_ARG, CMD_ROOT_DIR, FOLDER_TEST)
|
2019-04-28 16:33:22 +02:00
|
|
|
CMD_GREP_WALLET_ARGS = r"git grep --function-context 'void WalletInit::AddWalletOptions' -- {} | grep AddArg".format(CMD_ROOT_DIR)
|
|
|
|
CMD_GREP_WALLET_HIDDEN_ARGS = r"git grep --function-context 'void DummyWalletInit::AddWalletOptions' -- {}".format(CMD_ROOT_DIR)
|
2018-03-28 19:57:17 +02:00
|
|
|
CMD_GREP_DOCS = r"git grep --perl-regexp '{}' {}".format(REGEX_DOC, CMD_ROOT_DIR)
|
2016-01-04 02:06:04 +01:00
|
|
|
# list unsupported, deprecated and duplicate args as they need no documentation
|
2018-09-20 22:41:08 +02:00
|
|
|
SET_DOC_OPTIONAL = set(['-h', '-help', '-dbcrashratio', '-forcecompactdb'])
|
2016-01-04 02:06:04 +01:00
|
|
|
|
2018-03-28 19:57:17 +02:00
|
|
|
|
2019-04-28 16:33:22 +02:00
|
|
|
def lint_missing_argument_documentation():
|
|
|
|
used = check_output(CMD_GREP_ARGS, shell=True).decode('utf8').strip()
|
|
|
|
docd = check_output(CMD_GREP_DOCS, shell=True).decode('utf8').strip()
|
2018-03-28 19:57:17 +02:00
|
|
|
|
|
|
|
args_used = set(re.findall(re.compile(REGEX_ARG), used))
|
|
|
|
args_docd = set(re.findall(re.compile(REGEX_DOC), docd)).union(SET_DOC_OPTIONAL)
|
|
|
|
args_need_doc = args_used.difference(args_docd)
|
|
|
|
args_unknown = args_docd.difference(args_used)
|
|
|
|
|
|
|
|
print("Args used : {}".format(len(args_used)))
|
|
|
|
print("Args documented : {}".format(len(args_docd)))
|
|
|
|
print("Args undocumented: {}".format(len(args_need_doc)))
|
|
|
|
print(args_need_doc)
|
|
|
|
print("Args unknown : {}".format(len(args_unknown)))
|
|
|
|
print(args_unknown)
|
|
|
|
|
2019-04-28 16:33:22 +02:00
|
|
|
assert 0 == len(args_need_doc), "Please document the following arguments: {}".format(args_need_doc)
|
|
|
|
|
|
|
|
|
|
|
|
def lint_missing_hidden_wallet_args():
|
|
|
|
wallet_args = check_output(CMD_GREP_WALLET_ARGS, shell=True).decode('utf8').strip()
|
|
|
|
wallet_hidden_args = check_output(CMD_GREP_WALLET_HIDDEN_ARGS, shell=True).decode('utf8').strip()
|
|
|
|
|
|
|
|
wallet_args = set(re.findall(re.compile(REGEX_DOC), wallet_args))
|
|
|
|
wallet_hidden_args = set(re.findall(re.compile(r' "([^"=]+)'), wallet_hidden_args))
|
|
|
|
|
|
|
|
hidden_missing = wallet_args.difference(wallet_hidden_args)
|
|
|
|
if hidden_missing:
|
|
|
|
assert 0, "Please add {} to the hidden args in DummyWalletInit::AddWalletOptions".format(hidden_missing)
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
lint_missing_argument_documentation()
|
|
|
|
lint_missing_hidden_wallet_args()
|
2018-03-28 19:57:17 +02:00
|
|
|
|
2016-01-04 02:06:04 +01:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|