@click.command(name='check-dir')
@click.argument('directory')
-@click.option('-e', '--extension', default='py',
- help='File extension to search for.')
@click.option('-l', '--license', default='license-header.txt',
help='License header file to compare against.')
+@click.option('-r', '--regex', default='.+\.py$',
+ help='File regex pattern to match on when searching.')
@click.pass_context
-def check_directory(ctx, license, directory, extension):
+def check_directory(ctx, license, directory, regex):
"""Check directory for files missing license headers.
+ Uses a regex pattern to find files to check for approved license headers.
+
Does not care if about line formatting of the license as long as all of the
text is there and in the correct order.
Note: This code only supports '#' comments for license headers.
"""
- check_license_directory(license, directory, extension)
+ check_license_directory(license, directory, regex)
license.add_command(check)
return 0
-def check_license_directory(license_file, directory, extension="py"):
+def check_license_directory(license_file, directory, regex=".+\.py$"):
"""Search a directory for files and calls check_license()."""
missing_license = False
for root, dirs, files in os.walk(directory):
- for file in files:
- if file.endswith(".{}".format(extension)):
- if check_license(license_file, os.path.join(root, file)):
+ for f in files:
+ if re.search(regex, f):
+ if check_license(license_file, os.path.join(root, f)):
missing_license = True
if missing_license: