From 7246a0c800bc60475eecbe394fc2d68c2a7b5ff9 Mon Sep 17 00:00:00 2001 From: Trevor Royer Date: Wed, 24 Nov 2021 07:38:26 -0600 Subject: [PATCH] cli: Separate --format=auto logic Moved the auto arg_format selection out of the main if block into a separate logic section to improve readability. No logic changes. --- yamllint/cli.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/yamllint/cli.py b/yamllint/cli.py index cb87350..3fbb8b8 100644 --- a/yamllint/cli.py +++ b/yamllint/cli.py @@ -103,18 +103,22 @@ def show_problems(problems, file, args_format, no_warn): max_level = 0 first = True + if args_format == 'auto': + if ('GITHUB_ACTIONS' in os.environ and + 'GITHUB_WORKFLOW' in os.environ): + args_format = 'github' + elif supports_color(): + args_format = 'colored' + for problem in problems: max_level = max(max_level, PROBLEM_LEVELS[problem.level]) if no_warn and (problem.level != 'error'): continue if args_format == 'parsable': print(Format.parsable(problem, file)) - elif args_format == 'github' or (args_format == 'auto' and - 'GITHUB_ACTIONS' in os.environ and - 'GITHUB_WORKFLOW' in os.environ): + elif args_format == 'github': print(Format.github(problem, file)) - elif args_format == 'colored' or \ - (args_format == 'auto' and supports_color()): + elif args_format == 'colored': if first: print('\033[4m%s\033[0m' % file) first = False