Merge pull request #46194 from CaoShuFeng/under

Automatic merge from submit-queue (batch tested with PRs 46149, 45897, 46293, 46296, 46194)

check flag format in file known-flags.txt

All flags in file hack/verify-flags/known-flags.txt should contain
character -, this change check it to prevent adding useless flags
to known-flags.txt
ref #45948 

**Release note**:

```
NONE
```
pull/6/head
Kubernetes Submit Queue 2017-05-23 15:49:03 -07:00 committed by GitHub
commit c2421df336
1 changed files with 23 additions and 1 deletions

View File

@ -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)