diff --git a/README.md b/README.md index 60370ab..5ea7429 100644 --- a/README.md +++ b/README.md @@ -14,12 +14,16 @@ yamllint my_file.yml my_other_file.yaml ... ``` ```sh -yamllint -c ~/myconfig my_file.yml +yamllint . +``` + +```sh +yamllint -c ~/myconfig file.yml ``` ```sh # To output a format parsable (by editors like Vim, emacs, etc.) -yamllint -f parsable my_file.yml +yamllint -f parsable file.yml ``` ## Installation diff --git a/yamllint/cli.py b/yamllint/cli.py index 617f3a2..cc4d308 100644 --- a/yamllint/cli.py +++ b/yamllint/cli.py @@ -27,6 +27,17 @@ from yamllint.errors import YamlLintConfigError from yamllint import lint +def find_files_recursively(items): + for item in items: + if os.path.isdir(item): + for root, dirnames, filenames in os.walk(item): + for filename in [f for f in filenames + if f.endswith(('.yml', '.yaml'))]: + yield os.path.join(root, filename) + else: + yield item + + class Format(object): @staticmethod def parsable(problem, filename): @@ -55,7 +66,7 @@ class Format(object): def run(argv): parser = argparse.ArgumentParser(prog=APP_NAME, description=APP_DESCRIPTION) - parser.add_argument('files', metavar='FILES', nargs='+', + parser.add_argument('files', metavar='FILE_OR_DIR', nargs='+', help='files to check') parser.add_argument('-c', '--config', dest='config_file', action='store', help='path to a custom configuration') @@ -82,7 +93,7 @@ def run(argv): return_code = 0 - for file in args.files: + for file in find_files_recursively(args.files): if args.format != 'parsable': print('\033[4m%s\033[0m' % file)