12
12
13
13
from subprocess import check_output
14
14
import re
15
- import sys
16
15
17
16
FOLDER_GREP = 'src'
18
17
FOLDER_TEST = 'src/test/'
19
18
REGEX_ARG = '(?:ForceSet|SoftSet|Get|Is)(?:Bool)?Args?(?:Set)?\("(-[^"]+)"'
20
19
REGEX_DOC = 'AddArg\("(-[^"=]+?)(?:=|")'
21
- CMD_ROOT_DIR = '` git rev-parse --show-toplevel` /{}' .format (FOLDER_GREP )
20
+ CMD_ROOT_DIR = '$( git rev-parse --show-toplevel) /{}' .format (FOLDER_GREP )
22
21
CMD_GREP_ARGS = r"git grep --perl-regexp '{}' -- {} ':(exclude){}'" .format (REGEX_ARG , CMD_ROOT_DIR , FOLDER_TEST )
22
+ CMD_GREP_WALLET_ARGS = r"git grep --function-context 'void WalletInit::AddWalletOptions' -- {} | grep AddArg" .format (CMD_ROOT_DIR )
23
+ CMD_GREP_WALLET_HIDDEN_ARGS = r"git grep --function-context 'void DummyWalletInit::AddWalletOptions' -- {}" .format (CMD_ROOT_DIR )
23
24
CMD_GREP_DOCS = r"git grep --perl-regexp '{}' {}" .format (REGEX_DOC , CMD_ROOT_DIR )
24
25
# list unsupported, deprecated and duplicate args as they need no documentation
25
26
SET_DOC_OPTIONAL = set (['-h' , '-help' , '-dbcrashratio' , '-forcecompactdb' ])
26
27
27
28
28
- def main ():
29
- if sys .version_info >= (3 , 6 ):
30
- used = check_output (CMD_GREP_ARGS , shell = True , universal_newlines = True , encoding = 'utf8' )
31
- docd = check_output (CMD_GREP_DOCS , shell = True , universal_newlines = True , encoding = 'utf8' )
32
- else :
33
- used = check_output (CMD_GREP_ARGS , shell = True ).decode ('utf8' ).strip ()
34
- docd = check_output (CMD_GREP_DOCS , shell = True ).decode ('utf8' ).strip ()
29
+ def lint_missing_argument_documentation ():
30
+ used = check_output (CMD_GREP_ARGS , shell = True ).decode ('utf8' ).strip ()
31
+ docd = check_output (CMD_GREP_DOCS , shell = True ).decode ('utf8' ).strip ()
35
32
36
33
args_used = set (re .findall (re .compile (REGEX_ARG ), used ))
37
34
args_docd = set (re .findall (re .compile (REGEX_DOC ), docd )).union (SET_DOC_OPTIONAL )
@@ -45,7 +42,24 @@ def main():
45
42
print ("Args unknown : {}" .format (len (args_unknown )))
46
43
print (args_unknown )
47
44
48
- sys .exit (len (args_need_doc ))
45
+ assert 0 == len (args_need_doc ), "Please document the following arguments: {}" .format (args_need_doc )
46
+
47
+
48
+ def lint_missing_hidden_wallet_args ():
49
+ wallet_args = check_output (CMD_GREP_WALLET_ARGS , shell = True ).decode ('utf8' ).strip ()
50
+ wallet_hidden_args = check_output (CMD_GREP_WALLET_HIDDEN_ARGS , shell = True ).decode ('utf8' ).strip ()
51
+
52
+ wallet_args = set (re .findall (re .compile (REGEX_DOC ), wallet_args ))
53
+ wallet_hidden_args = set (re .findall (re .compile (r' "([^"=]+)' ), wallet_hidden_args ))
54
+
55
+ hidden_missing = wallet_args .difference (wallet_hidden_args )
56
+ if hidden_missing :
57
+ assert 0 , "Please add {} to the hidden args in DummyWalletInit::AddWalletOptions" .format (hidden_missing )
58
+
59
+
60
+ def main ():
61
+ lint_missing_argument_documentation ()
62
+ lint_missing_hidden_wallet_args ()
49
63
50
64
51
65
if __name__ == "__main__" :
0 commit comments