2017-12-12 11:47:24 -08:00
|
|
|
#!/usr/bin/env python3
|
2018-07-26 15:36:45 -07:00
|
|
|
# Copyright (c) 2015-2018 The Bitcoin Core developers
|
2016-01-03 17:06:04 -08: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
|
2017-07-09 13:57:02 -07:00
|
|
|
import sys
|
2016-01-03 17:06:04 -08:00
|
|
|
|
|
|
|
FOLDER_GREP = 'src'
|
|
|
|
FOLDER_TEST = 'src/test/'
|
2018-03-28 10:57:17 -07:00
|
|
|
REGEX_ARG = '(?:ForceSet|SoftSet|Get|Is)(?:Bool)?Args?(?:Set)?\("(-[^"]+)"'
|
2018-04-28 13:54:58 -07:00
|
|
|
REGEX_DOC = 'AddArg\("(-[^"=]+?)(?:=|")'
|
2017-12-12 11:47:24 -08:00
|
|
|
CMD_ROOT_DIR = '`git rev-parse --show-toplevel`/{}'.format(FOLDER_GREP)
|
2018-03-28 10:57:17 -07:00
|
|
|
CMD_GREP_ARGS = r"git grep --perl-regexp '{}' -- {} ':(exclude){}'".format(REGEX_ARG, CMD_ROOT_DIR, FOLDER_TEST)
|
|
|
|
CMD_GREP_DOCS = r"git grep --perl-regexp '{}' {}".format(REGEX_DOC, CMD_ROOT_DIR)
|
2016-01-03 17:06:04 -08:00
|
|
|
# list unsupported, deprecated and duplicate args as they need no documentation
|
2018-04-29 16:34:57 -07:00
|
|
|
SET_DOC_OPTIONAL = set(['-rpcssl', '-benchmark', '-h', '-help', '-socks', '-tor', '-debugnet', '-whitelistalwaysrelay', '-promiscuousmempoolflags', '-blockminsize', '-dbcrashratio', '-forcecompactdb', '-usehd'])
|
2016-01-03 17:06:04 -08:00
|
|
|
|
2018-03-28 10:57:17 -07:00
|
|
|
|
2016-01-03 17:06:04 -08:00
|
|
|
def main():
|
2018-03-28 10:57:17 -07:00
|
|
|
used = check_output(CMD_GREP_ARGS, shell=True, universal_newlines=True)
|
|
|
|
docd = check_output(CMD_GREP_DOCS, shell=True, universal_newlines=True)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
sys.exit(len(args_need_doc))
|
|
|
|
|
2016-01-03 17:06:04 -08:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|