From bc62215809ec62a07eb4e2b43b25166f2bed2d2f Mon Sep 17 00:00:00 2001 From: Edvard Majakari Date: Wed, 24 Aug 2022 07:48:47 +0300 Subject: [PATCH] Added --quiet option to suppress no issues (#89) --- autoflake.py | 4 +++- test_autoflake.py | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/autoflake.py b/autoflake.py index fb60f99..1935d3e 100755 --- a/autoflake.py +++ b/autoflake.py @@ -845,7 +845,7 @@ def fix_file(filename, args, standard_out): filename) standard_out.write(''.join(diff)) else: - if args.check: + if args.check and not args.quiet: standard_out.write('No issues detected!\n') else: _LOGGER.debug('Clean %s: nothing to fix', filename) @@ -1018,6 +1018,8 @@ def _main(argv, standard_out, standard_error): help='remove unused variables') parser.add_argument('--version', action='version', version='%(prog)s ' + __version__) + parser.add_argument('--quiet', action='store_true', + help='Suppress output if there are no issues') parser.add_argument('-v', '--verbose', action='count', dest='verbosity', default=0, help='print more verbose logs (you can ' 'repeat `-v` to make it more verbose)') diff --git a/test_autoflake.py b/test_autoflake.py index 19ec482..4a45f8f 100755 --- a/test_autoflake.py +++ b/test_autoflake.py @@ -1404,6 +1404,19 @@ def test_check_correct_file(self): standard_error=None) self.assertEqual('No issues detected!\n', output_file.getvalue()) + def test_check_correct_file_with_quiet(self): + with temporary_file("""\ +import foo +x = foo.bar +print(x) +""") as filename: + output_file = io.StringIO() + autoflake._main(argv=['my_fake_program', '--check', '--quiet', + filename], + standard_out=output_file, + standard_error=None) + self.assertEqual('', output_file.getvalue()) + def test_check_useless_pass(self): with temporary_file("""\ import foo