2 # Copyright (c) 2015-2016 The Bitcoin Core developers
3 # Distributed under the MIT software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
7 This checks if all command line args are documented.
8 Return value is 0 to indicate no error.
13 from subprocess
import check_output
18 FOLDER_TEST
= 'src/test/'
19 CMD_ROOT_DIR
= '`git rev-parse --show-toplevel`/%s' % FOLDER_GREP
20 CMD_GREP_ARGS
= r
"egrep -r -I '(map(Multi)?Args(\.count\(|\[)|Get(Bool)?Arg\()\"\
-[^
\"]+?
\"' %s | grep -v '%s'" % (CMD_ROOT_DIR, FOLDER_TEST)
21 CMD_GREP_DOCS = r"egrep -r -I 'HelpMessageOpt\
(\"\
-[^
\"=]+?
(=|
\")' %s" % (CMD_ROOT_DIR)
22 REGEX_ARG = re.compile(r'(?
:map(?
:Multi
)?
Args(?
:\
.count\
(|\
[)|
Get(?
:Bool
)?Arg\
()\"(\
-[^
\"]+?
)\"')
23 REGEX_DOC = re.compile(r'HelpMessageOpt\
(\"(\
-[^
\"=]+?
)(?
:=|
\")')
24 # list unsupported, deprecated and duplicate args as they need no documentation
25 SET_DOC_OPTIONAL = set(['-rpcssl
', '-benchmark
', '-h
', '-help', '-socks
', '-tor
', '-debugnet
', '-whitelistalwaysrelay
', '-prematurewitness
', '-walletprematurewitness
', '-promiscuousmempoolflags
', '-blockminsize
', '-dbcrashratio
', '-forcecompactdb
', '-usehd
'])
28 used = check_output(CMD_GREP_ARGS, shell=True)
29 docd = check_output(CMD_GREP_DOCS, shell=True)
31 args_used = set(re.findall(REGEX_ARG,used))
32 args_docd = set(re.findall(REGEX_DOC,docd)).union(SET_DOC_OPTIONAL)
33 args_need_doc = args_used.difference(args_docd)
34 args_unknown = args_docd.difference(args_used)
36 print "Args used : %s" % len(args_used)
37 print "Args documented : %s" % len(args_docd)
38 print "Args undocumented: %s" % len(args_need_doc)
40 print "Args unknown : %s" % len(args_unknown)
43 sys.exit(len(args_need_doc))
45 if __name__ == "__main__":