cli: Add --list-files command line option
This option lists the files to lint by yamllint, taking into account `ignore` and `yaml-files` configuration options.
This commit is contained in:
@@ -136,6 +136,13 @@ directories, set ``yaml-files`` configuration option. The default is:
|
|||||||
The same rules as for ignoring paths apply (``.gitignore``-style path pattern,
|
The same rules as for ignoring paths apply (``.gitignore``-style path pattern,
|
||||||
see below).
|
see below).
|
||||||
|
|
||||||
|
If you need to know the exact list of files that yamllint would process,
|
||||||
|
without really linting them, you can use ``--list-files``:
|
||||||
|
|
||||||
|
.. code:: bash
|
||||||
|
|
||||||
|
yamllint --list-files .
|
||||||
|
|
||||||
Ignoring paths
|
Ignoring paths
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
@@ -220,6 +227,13 @@ or:
|
|||||||
|
|
||||||
.. note:: However, this is mutually exclusive with the ``ignore`` key.
|
.. note:: However, this is mutually exclusive with the ``ignore`` key.
|
||||||
|
|
||||||
|
If you need to know the exact list of files that yamllint would process,
|
||||||
|
without really linting them, you can use ``--list-files``:
|
||||||
|
|
||||||
|
.. code:: bash
|
||||||
|
|
||||||
|
yamllint --list-files .
|
||||||
|
|
||||||
Setting the locale
|
Setting the locale
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
|
|||||||
@@ -678,6 +678,39 @@ class CommandLineTestCase(unittest.TestCase):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
(ctx.returncode, ctx.stdout, ctx.stderr), (1, expected_out, ''))
|
(ctx.returncode, ctx.stdout, ctx.stderr), (1, expected_out, ''))
|
||||||
|
|
||||||
|
def test_run_list_files(self):
|
||||||
|
with RunContext(self) as ctx:
|
||||||
|
cli.run(('--list-files', self.wd))
|
||||||
|
self.assertEqual(ctx.returncode, 0)
|
||||||
|
self.assertEqual(
|
||||||
|
sorted(ctx.stdout.splitlines()),
|
||||||
|
[os.path.join(self.wd, 'a.yaml'),
|
||||||
|
os.path.join(self.wd, 'c.yaml'),
|
||||||
|
os.path.join(self.wd, 'dos.yml'),
|
||||||
|
os.path.join(self.wd, 'empty.yml'),
|
||||||
|
os.path.join(self.wd, 'en.yaml'),
|
||||||
|
os.path.join(self.wd, 's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml'),
|
||||||
|
os.path.join(self.wd, 'sub/directory.yaml/empty.yml'),
|
||||||
|
os.path.join(self.wd, 'sub/ok.yaml'),
|
||||||
|
os.path.join(self.wd, 'warn.yaml')]
|
||||||
|
)
|
||||||
|
|
||||||
|
config = '{ignore: "*.yml", yaml-files: ["*.*"]}'
|
||||||
|
with RunContext(self) as ctx:
|
||||||
|
cli.run(('--list-files', '-d', config, self.wd))
|
||||||
|
self.assertEqual(ctx.returncode, 0)
|
||||||
|
self.assertEqual(
|
||||||
|
sorted(ctx.stdout.splitlines()),
|
||||||
|
[os.path.join(self.wd, 'a.yaml'),
|
||||||
|
os.path.join(self.wd, 'c.yaml'),
|
||||||
|
os.path.join(self.wd, 'en.yaml'),
|
||||||
|
os.path.join(self.wd, 'no-yaml.json'),
|
||||||
|
os.path.join(self.wd, 's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml'),
|
||||||
|
os.path.join(self.wd, 'sub/directory.yaml/not-yaml.txt'),
|
||||||
|
os.path.join(self.wd, 'sub/ok.yaml'),
|
||||||
|
os.path.join(self.wd, 'warn.yaml')]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class CommandLineConfigTestCase(unittest.TestCase):
|
class CommandLineConfigTestCase(unittest.TestCase):
|
||||||
def test_config_file(self):
|
def test_config_file(self):
|
||||||
|
|||||||
@@ -157,6 +157,8 @@ def run(argv=None):
|
|||||||
config_group.add_argument('-d', '--config-data', dest='config_data',
|
config_group.add_argument('-d', '--config-data', dest='config_data',
|
||||||
action='store',
|
action='store',
|
||||||
help='custom configuration (as YAML source)')
|
help='custom configuration (as YAML source)')
|
||||||
|
parser.add_argument('--list-files', action='store_true', dest='list_files',
|
||||||
|
help='list files to lint and exit')
|
||||||
parser.add_argument('-f', '--format',
|
parser.add_argument('-f', '--format',
|
||||||
choices=('parsable', 'standard', 'colored', 'github',
|
choices=('parsable', 'standard', 'colored', 'github',
|
||||||
'auto'),
|
'auto'),
|
||||||
@@ -207,6 +209,12 @@ def run(argv=None):
|
|||||||
if conf.locale is not None:
|
if conf.locale is not None:
|
||||||
locale.setlocale(locale.LC_ALL, conf.locale)
|
locale.setlocale(locale.LC_ALL, conf.locale)
|
||||||
|
|
||||||
|
if args.list_files:
|
||||||
|
for file in find_files_recursively(args.files, conf):
|
||||||
|
if not conf.is_file_ignored(file):
|
||||||
|
print(file)
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
max_level = 0
|
max_level = 0
|
||||||
|
|
||||||
for file in find_files_recursively(args.files, conf):
|
for file in find_files_recursively(args.files, conf):
|
||||||
|
|||||||
Reference in New Issue
Block a user