From a3d8b4b275c9f3d227657741f32a449f0edb8b3b Mon Sep 17 00:00:00 2001 From: Eric Brown Date: Tue, 15 Feb 2022 05:04:53 -0800 Subject: [PATCH] Show usage with no arguments (#814) The current behavior is to display an error when no arguments are given that no files were found. This is a non-standard way for a command line. Rather than an error message, no arguments should display the usage of the command itself. Signed-off-by: Eric Brown --- bandit/cli/main.py | 3 ++- tests/functional/test_runtime.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bandit/cli/main.py b/bandit/cli/main.py index fd436d1f5..65fd280e2 100644 --- a/bandit/cli/main.py +++ b/bandit/cli/main.py @@ -586,8 +586,9 @@ def main(): ) if not args.targets: - LOG.error("No targets found in CLI or ini files, exiting.") + parser.print_usage() sys.exit(2) + # if the log format string was set in the options, reinitialize if b_conf.get_option("log_format"): log_format = b_conf.get_option("log_format") diff --git a/tests/functional/test_runtime.py b/tests/functional/test_runtime.py index de8236465..a9eb21608 100644 --- a/tests/functional/test_runtime.py +++ b/tests/functional/test_runtime.py @@ -32,7 +32,7 @@ def test_no_arguments(self): ] ) self.assertEqual(2, retcode) - self.assertIn("No targets found in CLI or ini files", output) + self.assertIn("usage: bandit [-h]", output) def test_piped_input(self): with open("examples/imports.py") as infile: