diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b1af8e854..6a401e7704 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 This changelog format was introduced in NAV 5.4.0. Older changelogs can be found in the [HISTORY](HISTORY) file. +## Unreleased + +### Fixed + +#### User-visible fixes +- Show help text when running nav command without arguments instead of error ([#2601](https://github.com/Uninett/nav/issues/2601), [#2603](https://github.com/Uninett/nav/pull/2603)) + ## [5.6.1] - 2023-03-23 ### Fixed diff --git a/bin/nav b/bin/nav index 6e3e030d8e..11f67f83f4 100755 --- a/bin/nav +++ b/bin/nav @@ -47,8 +47,13 @@ except (OSError, CrontabError) as _error: def main(args): """Main execution point""" - args = make_argparser().parse_args() - args.func(args) + parser = make_argparser() + args = parser.parse_args() + try: + args.func(args) + except AttributeError: + parser.print_help(sys.stderr) + sys.exit(0) def make_argparser(): diff --git a/tests/integration/bin_test.py b/tests/integration/bin_test.py index d0f6f791d6..72a7fb3920 100644 --- a/tests/integration/bin_test.py +++ b/tests/integration/bin_test.py @@ -36,3 +36,25 @@ def test_naventity_runs_without_error_with_arguments(localhost, snmpsim): print(fail.decode('utf-8')) assert retcode == 0 + + +def test_nav_runs_without_error_without_arguments(): + """ + Verifies that nav runs with a zero exit code when given no arguments + + Added in regards to: https://github.com/Uninett/nav/issues/2601 + """ + proc = subprocess.Popen( + ["./bin/nav"], + stderr=subprocess.STDOUT, + stdout=subprocess.PIPE, + ) + (done, fail) = proc.communicate() + retcode = proc.wait() + + if done: + print(done.decode('utf-8')) + if fail: + print(fail.decode('utf-8')) + + assert retcode == 0