mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-04-24 15:27:17 +00:00
feat: show help message if no command specified
This commit is contained in:
parent
6fcb5449c3
commit
62ae3ada4a
@ -90,7 +90,7 @@ def _parser() -> argparse.ArgumentParser:
|
||||
type=int, default=-1)
|
||||
parser.add_argument("-V", "--version", action="version", version=__version__)
|
||||
|
||||
subparsers = parser.add_subparsers(title="command", help="command to run", dest="command", required=True)
|
||||
subparsers = parser.add_subparsers(title="command", help="command to run", dest="command")
|
||||
|
||||
_set_aur_search_parser(subparsers)
|
||||
_set_help_parser(subparsers)
|
||||
@ -1016,5 +1016,8 @@ def run() -> int:
|
||||
args_parser = _parser()
|
||||
args = args_parser.parse_args()
|
||||
|
||||
if args.command is None: # in case of empty command we would like to print help message
|
||||
args_parser.exit(status=2, message=args_parser.format_help())
|
||||
|
||||
handler: handlers.Handler = args.handler
|
||||
return handler.execute(args)
|
||||
|
@ -1,4 +1,5 @@
|
||||
import argparse
|
||||
import pytest
|
||||
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
@ -841,8 +842,20 @@ def test_run(args: argparse.Namespace, mocker: MockerFixture) -> None:
|
||||
application must be run
|
||||
"""
|
||||
args.architecture = "x86_64"
|
||||
args.command = ""
|
||||
args.handler = Handler
|
||||
|
||||
mocker.patch("argparse.ArgumentParser.parse_args", return_value=args)
|
||||
|
||||
assert ahriman.run() == 1
|
||||
|
||||
|
||||
def test_run_without_command(args: argparse.Namespace, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must show help message if run without commands
|
||||
"""
|
||||
args.command = None
|
||||
mocker.patch("argparse.ArgumentParser.parse_args", return_value=args)
|
||||
|
||||
with pytest.raises(SystemExit):
|
||||
ahriman.run()
|
||||
|
Loading…
Reference in New Issue
Block a user