Skip to content

Commit 1360844

Browse files
author
MarcoFalke
committed
contrib: Fix check-doc script regexes
1 parent 624bee9 commit 1360844

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

contrib/devtools/check-doc.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,33 @@
1616

1717
FOLDER_GREP = 'src'
1818
FOLDER_TEST = 'src/test/'
19+
REGEX_ARG = '(?:ForceSet|SoftSet|Get|Is)(?:Bool)?Args?(?:Set)?\("(-[^"]+)"'
20+
REGEX_DOC = 'HelpMessageOpt\("(-[^"=]+?)(?:=|")'
1921
CMD_ROOT_DIR = '`git rev-parse --show-toplevel`/{}'.format(FOLDER_GREP)
20-
CMD_GREP_ARGS = r"egrep -r -I '(map(Multi)?Args(\.count\(|\[)|Get(Bool)?Arg\()\"\-[^\"]+?\"' {} | grep -v '{}'".format(CMD_ROOT_DIR, FOLDER_TEST)
21-
CMD_GREP_DOCS = r"egrep -r -I 'HelpMessageOpt\(\"\-[^\"=]+?(=|\")' {}".format(CMD_ROOT_DIR)
22-
REGEX_ARG = re.compile(r'(?:map(?:Multi)?Args(?:\.count\(|\[)|Get(?:Bool)?Arg\()\"(\-[^\"]+?)\"')
23-
REGEX_DOC = re.compile(r'HelpMessageOpt\(\"(\-[^\"=]+?)(?:=|\")')
22+
CMD_GREP_ARGS = r"git grep --perl-regexp '{}' -- {} ':(exclude){}'".format(REGEX_ARG, CMD_ROOT_DIR, FOLDER_TEST)
23+
CMD_GREP_DOCS = r"git grep --perl-regexp '{}' {}".format(REGEX_DOC, CMD_ROOT_DIR)
2424
# list unsupported, deprecated and duplicate args as they need no documentation
2525
SET_DOC_OPTIONAL = set(['-rpcssl', '-benchmark', '-h', '-help', '-socks', '-tor', '-debugnet', '-whitelistalwaysrelay', '-prematurewitness', '-walletprematurewitness', '-promiscuousmempoolflags', '-blockminsize', '-dbcrashratio', '-forcecompactdb', '-usehd'])
2626

27+
2728
def main():
28-
used = check_output(CMD_GREP_ARGS, shell=True, universal_newlines=True)
29-
docd = check_output(CMD_GREP_DOCS, shell=True, universal_newlines=True)
30-
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)
35-
36-
print("Args used : {}".format(len(args_used)))
37-
print("Args documented : {}".format(len(args_docd)))
38-
print("Args undocumented: {}".format(len(args_need_doc)))
39-
print(args_need_doc)
40-
print("Args unknown : {}".format(len(args_unknown)))
41-
print(args_unknown)
42-
43-
sys.exit(len(args_need_doc))
29+
used = check_output(CMD_GREP_ARGS, shell=True, universal_newlines=True)
30+
docd = check_output(CMD_GREP_DOCS, shell=True, universal_newlines=True)
31+
32+
args_used = set(re.findall(re.compile(REGEX_ARG), used))
33+
args_docd = set(re.findall(re.compile(REGEX_DOC), docd)).union(SET_DOC_OPTIONAL)
34+
args_need_doc = args_used.difference(args_docd)
35+
args_unknown = args_docd.difference(args_used)
36+
37+
print("Args used : {}".format(len(args_used)))
38+
print("Args documented : {}".format(len(args_docd)))
39+
print("Args undocumented: {}".format(len(args_need_doc)))
40+
print(args_need_doc)
41+
print("Args unknown : {}".format(len(args_unknown)))
42+
print(args_unknown)
43+
44+
sys.exit(len(args_need_doc))
45+
4446

4547
if __name__ == "__main__":
4648
main()

0 commit comments

Comments
 (0)