Skip to content

Commit

Permalink
Show usage with no arguments (#814)
Browse files Browse the repository at this point in the history
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 <browne@vmware.com>
  • Loading branch information
ericwb committed Feb 15, 2022
1 parent b8ff685 commit a3d8b4b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion bandit/cli/main.py
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_runtime.py
Expand Up @@ -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:
Expand Down

0 comments on commit a3d8b4b

Please sign in to comment.