diff --git a/src/ytdl_sub/cli/parsers/dl.py b/src/ytdl_sub/cli/parsers/dl.py index 39c28626..a3ada3b3 100644 --- a/src/ytdl_sub/cli/parsers/dl.py +++ b/src/ytdl_sub/cli/parsers/dl.py @@ -1,6 +1,7 @@ import hashlib import re import shlex +from typing import Any from typing import Dict from typing import List from typing import Tuple @@ -116,7 +117,7 @@ class DownloadArgsParser: return largest_consecutive + 1 @classmethod - def _argument_name_and_value_to_dict(cls, arg_name: str, arg_value: str) -> Dict: + def _argument_name_and_value_to_dict(cls, arg_name: str, arg_value: Any) -> Dict: """ :param arg_name: Argument name in the form of 'key1.key2.key3' :param arg_value: Argument value @@ -134,14 +135,15 @@ class DownloadArgsParser: next_dict[arg_name_split[-1]] = arg_value - if arg_value == "True": - next_dict[arg_name_split[-1]] = True - elif arg_value == "False": - next_dict[arg_name_split[-1]] = False - elif arg_value.isdigit(): - next_dict[arg_name_split[-1]] = int(arg_value) - elif arg_value.replace(".", "", 1).isdigit(): - next_dict[arg_name_split[-1]] = float(arg_value) + if isinstance(arg_value, str): + if arg_value == "True": + next_dict[arg_name_split[-1]] = True + elif arg_value == "False": + next_dict[arg_name_split[-1]] = False + elif arg_value.isdigit(): + next_dict[arg_name_split[-1]] = int(arg_value) + elif arg_value.replace(".", "", 1).isdigit(): + next_dict[arg_name_split[-1]] = float(arg_value) return argument_dict diff --git a/tests/unit/cli/test_download_args_parser.py b/tests/unit/cli/test_download_args_parser.py index 56e2f874..675f4066 100644 --- a/tests/unit/cli/test_download_args_parser.py +++ b/tests/unit/cli/test_download_args_parser.py @@ -97,6 +97,26 @@ class TestDownloadArgsParser: "dl --parameter.not.using.list[0] 'v0'", {"parameter": {"not": {"using": {"list[0]": "v0"}}}}, ), + ( + None, + "dl --a.float.parameter 1.3", + {"a": {"float": {"parameter": 1.3}}}, + ), + ( + None, + "dl --a.int.parameter 6", + {"a": {"int": {"parameter": 6}}}, + ), + ( + None, + "dl --a.true.parameter True", + {"a": {"true": {"parameter": True}}}, + ), + ( + None, + "dl --a.false.parameter False", + {"a": {"false": {"parameter": False}}}, + ), ], ) def test_successful_args(self, config_options_generator, aliases, cmd, expected_sub_dict):