Skip to content

Commit

Permalink
fix(cli): Run extra args checks for aliases as well
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Oct 14, 2019
1 parent 80de724 commit cb70dae
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/aria2p/cli.py
Expand Up @@ -100,7 +100,7 @@ def check_args(parser, args):
"""Additional checks for command line arguments."""
subparser = [action for action in parser._actions if isinstance(action, argparse._SubParsersAction)][0].choices

if args.subcommand in ("pause", "remove", "resume", "purge"):
if args.subcommand in ("pause", "stop", "remove", "rm", "del", "delete", "resume", "start", "purge", "clear"):
if not args.do_all and not args.gids:
subparser[args.subcommand].error("the following arguments are required: gids or --all")
elif args.do_all and args.gids:
Expand Down
23 changes: 17 additions & 6 deletions tests/test_cli.py
Expand Up @@ -39,12 +39,23 @@ def test_parser_error_when_gids_and_all_option(capsys):


def test_parser_error_when_no_gid_and_no_all_option(capsys):
with pytest.raises(SystemExit) as e:
assert cli.main(["resume"])
assert e.value.code == 2
lines = err_lines(capsys)
assert lines[0].startswith("usage: aria2p resume")
assert lines[1].endswith("the following arguments are required: gids or --all")
def assert_func(command, alias):
with pytest.raises(SystemExit) as e:
cli.main([alias])
assert e.value.code == 2
lines = err_lines(capsys)
assert lines[0].startswith("usage: aria2p " + command)
assert lines[1].endswith("the following arguments are required: gids or --all")

for command, aliases in [
("pause", ["stop"]),
("remove", ["rm", "del", "delete"]),
("resume", ["start"]),
("purge", ["clear"]),
]:
assert_func(command, command)
for alias in aliases:
assert_func(command, alias)


@patch("aria2p.cli.subcommand_purge")
Expand Down

0 comments on commit cb70dae

Please sign in to comment.