Улучшение обработки аргументов
This commit is contained in:
parent
1d944cc9fb
commit
5268b87e0d
2 changed files with 5 additions and 21 deletions
|
|
@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
|
||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "yandex-music-downloader"
|
name = "yandex-music-downloader"
|
||||||
version = "3.5.1"
|
version = "3.5.2"
|
||||||
description = "Загрузчик музыки с сервиса Яндекс.Музыка"
|
description = "Загрузчик музыки с сервиса Яндекс.Музыка"
|
||||||
requires-python = ">=3.9"
|
requires-python = ">=3.9"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
|
|
||||||
24
ymd/cli.py
24
ymd/cli.py
|
|
@ -34,24 +34,6 @@ def show_default(text: Optional[str] = None) -> str:
|
||||||
return f"{text} ({default})"
|
return f"{text} ({default})"
|
||||||
|
|
||||||
|
|
||||||
def quality_arg(astr: str) -> int:
|
|
||||||
aint = int(astr)
|
|
||||||
if 0 <= aint <= 2:
|
|
||||||
return aint
|
|
||||||
raise ArgumentTypeError("Значение должно быть в промежутке от 0 до 2")
|
|
||||||
|
|
||||||
|
|
||||||
def compatibility_level_arg(astr: str) -> int:
|
|
||||||
aint = int(astr)
|
|
||||||
min_val = core.MIN_COMPATIBILITY_LEVEL
|
|
||||||
max_val = core.MAX_COMPATIBILITY_LEVEL
|
|
||||||
if min_val <= aint <= max_val:
|
|
||||||
return aint
|
|
||||||
raise ArgumentTypeError(
|
|
||||||
f"Значение должен быть в промежутке от {min_val} до {max_val}"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def checked_int_arg(
|
def checked_int_arg(
|
||||||
min_value: int, max_value: Optional[int] = None
|
min_value: int, max_value: Optional[int] = None
|
||||||
) -> Callable[[str], int]:
|
) -> Callable[[str], int]:
|
||||||
|
|
@ -91,7 +73,7 @@ def main():
|
||||||
"--quality",
|
"--quality",
|
||||||
metavar="<Качество>",
|
metavar="<Качество>",
|
||||||
default=0,
|
default=0,
|
||||||
type=quality_arg,
|
type=checked_int_arg(0, 2),
|
||||||
help="Качество трека:\n0 - Низкое (AAC 64kbps)\n1 - Оптимальное (AAC 192kbps)\n2 - Лучшее (FLAC)\n(по умолчанию: %(default)s)",
|
help="Качество трека:\n0 - Низкое (AAC 64kbps)\n1 - Оптимальное (AAC 192kbps)\n2 - Лучшее (FLAC)\n(по умолчанию: %(default)s)",
|
||||||
)
|
)
|
||||||
common_group.add_argument(
|
common_group.add_argument(
|
||||||
|
|
@ -140,7 +122,9 @@ def main():
|
||||||
"--compatibility-level",
|
"--compatibility-level",
|
||||||
metavar="<Уровень совместимости>",
|
metavar="<Уровень совместимости>",
|
||||||
default=1,
|
default=1,
|
||||||
type=compatibility_level_arg,
|
type=checked_int_arg(
|
||||||
|
core.MIN_COMPATIBILITY_LEVEL, core.MAX_COMPATIBILITY_LEVEL
|
||||||
|
),
|
||||||
help=show_default(
|
help=show_default(
|
||||||
f"Уровень совместимости, от {core.MIN_COMPATIBILITY_LEVEL} до {core.MAX_COMPATIBILITY_LEVEL}. См. README для подробного описания"
|
f"Уровень совместимости, от {core.MIN_COMPATIBILITY_LEVEL} до {core.MAX_COMPATIBILITY_LEVEL}. См. README для подробного описания"
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue