Skip to content

Commit

Permalink
fix: Fix checking arguments of add-torrent and add-metalink
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Dec 17, 2021
1 parent 41c9ea3 commit fa9ede5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 2 additions & 0 deletions config/flake8.ini
Expand Up @@ -82,6 +82,8 @@ ignore =
WPS226
# too many public instance attributes
WPS230
# too high module complexity
WPS232
# too complex f-string
WPS237
# f-strings
Expand Down
13 changes: 10 additions & 3 deletions src/aria2p/cli/parser.py
Expand Up @@ -49,9 +49,16 @@ def check_args(parser: argparse.ArgumentParser, opts: argparse.Namespace) -> Non
subparsers[opts.subcommand].error("the following arguments are required: gids or --all")
elif opts.do_all and opts.gids:
subparsers[opts.subcommand].error("argument -a/--all: not allowed with arguments gids")
elif opts.subcommand and opts.subcommand.startswith("add"):
if not opts.uris and not opts.from_file:
subparsers[opts.subcommand].error("the following arguments are required: uris")
elif opts.subcommand:
if opts.subcommand in {"add", "add-magnet", "add-magnets"}:
if not opts.uris and not opts.from_file:
subparsers[opts.subcommand].error("the following arguments are required: uris")
elif opts.subcommand.startswith("add-torrent"):
if not opts.torrent_files and not opts.from_file:
subparsers[opts.subcommand].error("the following arguments are required: torrent_files")
elif opts.subcommand.startswith("add-metalink"):
if not opts.metalink_files and not opts.from_file:
subparsers[opts.subcommand].error("the following arguments are required: metalink_files")


def parse_options_string(options_string: str = None) -> dict:
Expand Down
10 changes: 10 additions & 0 deletions tests/test_cli.py
Expand Up @@ -246,3 +246,13 @@ def test_parse_invalid_options(command, capsys):
with pytest.raises(SystemExit):
opts = parser.parse_args([command, "http://example.com", "-o", "opt1"])
assert "Options strings must follow this format" in capsys.readouterr().err


@pytest.mark.parametrize(
("command", "option"),
[("add", "uris"), ("add-magnet", "uris"), ("add-torrent", "torrent_files"), ("add-metalink", "metalink_files")],
)
def test_error_when_missing_arg(command, option, capsys):
with pytest.raises(SystemExit):
main([command])
assert option in capsys.readouterr().err

0 comments on commit fa9ede5

Please sign in to comment.