|
|
@ -83,11 +83,41 @@ class Format(object):
|
|
|
|
return line
|
|
|
|
return line
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def show_problems(problems, file, args_format):
|
|
|
|
|
|
|
|
max_level = 0
|
|
|
|
|
|
|
|
first = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for problem in problems:
|
|
|
|
|
|
|
|
if args_format == 'parsable':
|
|
|
|
|
|
|
|
print(Format.parsable(problem, file))
|
|
|
|
|
|
|
|
elif args_format == 'colored' or \
|
|
|
|
|
|
|
|
(args_format == 'auto' and supports_color()):
|
|
|
|
|
|
|
|
if first:
|
|
|
|
|
|
|
|
print('\033[4m%s\033[0m' % file)
|
|
|
|
|
|
|
|
first = False
|
|
|
|
|
|
|
|
print(Format.standard_color(problem, file))
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
if first:
|
|
|
|
|
|
|
|
print(file)
|
|
|
|
|
|
|
|
first = False
|
|
|
|
|
|
|
|
print(Format.standard(problem, file))
|
|
|
|
|
|
|
|
max_level = max(max_level, PROBLEM_LEVELS[problem.level])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not first and args_format != 'parsable':
|
|
|
|
|
|
|
|
print('')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return max_level
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def run(argv=None):
|
|
|
|
def run(argv=None):
|
|
|
|
parser = argparse.ArgumentParser(prog=APP_NAME,
|
|
|
|
parser = argparse.ArgumentParser(prog=APP_NAME,
|
|
|
|
description=APP_DESCRIPTION)
|
|
|
|
description=APP_DESCRIPTION)
|
|
|
|
parser.add_argument('files', metavar='FILE_OR_DIR', nargs='+',
|
|
|
|
files_group = parser.add_mutually_exclusive_group(required=True)
|
|
|
|
help='files to check')
|
|
|
|
files_group.add_argument('files', metavar='FILE_OR_DIR', nargs='*',
|
|
|
|
|
|
|
|
default=(),
|
|
|
|
|
|
|
|
help='files to check')
|
|
|
|
|
|
|
|
files_group.add_argument('-', action='store_true', dest='stdin',
|
|
|
|
|
|
|
|
help='read from standard input')
|
|
|
|
config_group = parser.add_mutually_exclusive_group()
|
|
|
|
config_group = parser.add_mutually_exclusive_group()
|
|
|
|
config_group.add_argument('-c', '--config-file', dest='config_file',
|
|
|
|
config_group.add_argument('-c', '--config-file', dest='config_file',
|
|
|
|
action='store',
|
|
|
|
action='store',
|
|
|
@ -105,8 +135,6 @@ def run(argv=None):
|
|
|
|
parser.add_argument('-v', '--version', action='version',
|
|
|
|
parser.add_argument('-v', '--version', action='version',
|
|
|
|
version='{} {}'.format(APP_NAME, APP_VERSION))
|
|
|
|
version='{} {}'.format(APP_NAME, APP_VERSION))
|
|
|
|
|
|
|
|
|
|
|
|
# TODO: read from stdin when no filename?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
args = parser.parse_args(argv)
|
|
|
|
args = parser.parse_args(argv)
|
|
|
|
|
|
|
|
|
|
|
|
# User-global config is supposed to be in ~/.config/yamllint/config
|
|
|
|
# User-global config is supposed to be in ~/.config/yamllint/config
|
|
|
@ -138,32 +166,23 @@ def run(argv=None):
|
|
|
|
for file in find_files_recursively(args.files):
|
|
|
|
for file in find_files_recursively(args.files):
|
|
|
|
filepath = file[2:] if file.startswith('./') else file
|
|
|
|
filepath = file[2:] if file.startswith('./') else file
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
first = True
|
|
|
|
|
|
|
|
with open(file) as f:
|
|
|
|
with open(file) as f:
|
|
|
|
for problem in linter.run(f, conf, filepath):
|
|
|
|
problems = linter.run(f, conf, filepath)
|
|
|
|
if args.format == 'parsable':
|
|
|
|
except EnvironmentError as e:
|
|
|
|
print(Format.parsable(problem, file))
|
|
|
|
print(e, file=sys.stderr)
|
|
|
|
elif args.format == 'colored' or \
|
|
|
|
sys.exit(-1)
|
|
|
|
(args.format == 'auto' and supports_color()):
|
|
|
|
prob_level = show_problems(problems, file, args_format=args.format)
|
|
|
|
if first:
|
|
|
|
max_level = max(max_level, prob_level)
|
|
|
|
print('\033[4m%s\033[0m' % file)
|
|
|
|
|
|
|
|
first = False
|
|
|
|
# read yaml from stdin
|
|
|
|
|
|
|
|
if args.stdin:
|
|
|
|
print(Format.standard_color(problem, file))
|
|
|
|
try:
|
|
|
|
else:
|
|
|
|
problems = linter.run(sys.stdin, conf, '')
|
|
|
|
if first:
|
|
|
|
|
|
|
|
print(file)
|
|
|
|
|
|
|
|
first = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print(Format.standard(problem, file))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
max_level = max(max_level, PROBLEM_LEVELS[problem.level])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not first and args.format != 'parsable':
|
|
|
|
|
|
|
|
print('')
|
|
|
|
|
|
|
|
except EnvironmentError as e:
|
|
|
|
except EnvironmentError as e:
|
|
|
|
print(e, file=sys.stderr)
|
|
|
|
print(e, file=sys.stderr)
|
|
|
|
sys.exit(-1)
|
|
|
|
sys.exit(-1)
|
|
|
|
|
|
|
|
prob_level = show_problems(problems, 'stdin', args_format=args.format)
|
|
|
|
|
|
|
|
max_level = max(max_level, prob_level)
|
|
|
|
|
|
|
|
|
|
|
|
if max_level == PROBLEM_LEVELS['error']:
|
|
|
|
if max_level == PROBLEM_LEVELS['error']:
|
|
|
|
return_code = 1
|
|
|
|
return_code = 1
|
|
|
|