|
| 1 | +#!/usr/bin/env python |
| 2 | +# Copyright (c) 2014 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. |
| 5 | + |
| 6 | +''' |
| 7 | +This checks if all command line args are documented. |
| 8 | +Return value is 0 to indicate no error. |
| 9 | +
|
| 10 | +Author: @MarcoFalke |
| 11 | +''' |
| 12 | + |
| 13 | +from subprocess import check_output |
| 14 | +import re |
| 15 | + |
| 16 | +FOLDER_GREP = 'src' |
| 17 | +FOLDER_TEST = 'src/test/' |
| 18 | +CMD_ROOT_DIR = '`git rev-parse --show-toplevel`/%s' % FOLDER_GREP |
| 19 | +CMD_GREP_ARGS = r"egrep -r -I '(map(Multi)?Args(\.count\(|\[)|Get(Bool)?Arg\()\"\-[^\"]+?\"' %s | grep -v '%s'" % (CMD_ROOT_DIR, FOLDER_TEST) |
| 20 | +CMD_GREP_DOCS = r"egrep -r -I 'HelpMessageOpt\(\"\-[^\"=]+?(=|\")' %s" % (CMD_ROOT_DIR) |
| 21 | +REGEX_ARG = re.compile(r'(?:map(?:Multi)?Args(?:\.count\(|\[)|Get(?:Bool)?Arg\()\"(\-[^\"]+?)\"') |
| 22 | +REGEX_DOC = re.compile(r'HelpMessageOpt\(\"(\-[^\"=]+?)(?:=|\")') |
| 23 | +# list unsupported, deprecated and duplicate args as they need no documentation |
| 24 | +SET_DOC_OPTIONAL = set(['-rpcssl', '-benchmark', '-h', '-help', '-socks', '-tor', '-debugnet']) |
| 25 | + |
| 26 | +def main(): |
| 27 | + used = check_output(CMD_GREP_ARGS, shell=True) |
| 28 | + docd = check_output(CMD_GREP_DOCS, shell=True) |
| 29 | + |
| 30 | + args_used = set(re.findall(REGEX_ARG,used)) |
| 31 | + args_docd = set(re.findall(REGEX_DOC,docd)).union(SET_DOC_OPTIONAL) |
| 32 | + args_need_doc = args_used.difference(args_docd) |
| 33 | + args_unknown = args_docd.difference(args_used) |
| 34 | + |
| 35 | + print "Args used : %s" % len(args_used) |
| 36 | + print "Args documented : %s" % len(args_docd) |
| 37 | + print "Args undocumented: %s" % len(args_need_doc) |
| 38 | + print args_need_doc |
| 39 | + print "Args unknown : %s" % len(args_unknown) |
| 40 | + print args_unknown |
| 41 | + |
| 42 | + exit(len(args_need_doc)) |
| 43 | + |
| 44 | +if __name__ == "__main__": |
| 45 | + main() |
0 commit comments