From 3aa71aa1932dd54956c4d4178faf83ac1b554579 Mon Sep 17 00:00:00 2001 From: Cao Shufeng Date: Mon, 22 May 2017 10:51:04 +0800 Subject: [PATCH] check flag format in file known-flags.txt All flags in file hack/verify-flags/known-flags.txt should contain character -, this change check this to prevent adding useless flags to known-flags.txt --- hack/verify-flags-underscore.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/hack/verify-flags-underscore.py b/hack/verify-flags-underscore.py index c7b46421a7..073864b25f 100755 --- a/hack/verify-flags-underscore.py +++ b/hack/verify-flags-underscore.py @@ -120,6 +120,26 @@ def line_has_bad_flag(line, flagre): return True return False +def check_known_flags(rootdir): + pathname = os.path.join(rootdir, "hack/verify-flags/known-flags.txt") + f = open(pathname, 'r') + flags = set(f.read().splitlines()) + f.close() + + illegal_known_flags = set() + for flag in flags: + if len(flag) > 0: + if not "-" in flag: + illegal_known_flags.add(flag) + + if len(illegal_known_flags) != 0: + print("All flags in hack/verify-flags/known-flags.txt should contain character -, found these flags without -") + l = list(illegal_known_flags) + l.sort() + print("%s" % "\n".join(l)) + sys.exit(1) + + # The list of files might not be the whole repo. If someone only changed a # couple of files we don't want to run all of the golang files looking for # flags. Instead load the list of flags from hack/verify-flags/known-flags.txt @@ -174,7 +194,7 @@ def get_flags(rootdir, files): print("%s" % "\n".join(l)) sys.exit(1) if len(new_flags) != 0: - print("Found flags in golang files not in the list of known flags. Please add these to hack/verify-flags/known-flags.txt") + print("Found flags with character - in golang files not in the list of known flags. Please add these to hack/verify-flags/known-flags.txt") l = list(new_flags) l.sort() print("%s" % "\n".join(l)) @@ -223,6 +243,8 @@ def main(): files = get_all_files(rootdir) files = normalize_files(rootdir, files) + check_known_flags(rootdir) + flags = get_flags(rootdir, files) flagRE = flags_to_re(flags)