Skip to content

Commit

Permalink
Merge pull request #2603 from johannaengland/bugfix/nav-command-no-ar…
Browse files Browse the repository at this point in the history
…guments

Show help text when running nav command without arguments
  • Loading branch information
johannaengland authored Mar 31, 2023
2 parents cbfc888 + ee2baf5 commit b7190b9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions bin/nav
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
22 changes: 22 additions & 0 deletions tests/integration/bin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b7190b9

Please sign in to comment.