mirror of
https://github.com/mkb79/audible-cli.git
synced 2025-04-18 20:04:53 -04:00
Optimize error handling in cmd_download.py
The current change replaces generic `click.Abort()` statements with `click.BadOptionUsage()` to provide clearer error messages. These updates occur when there are conflicts in options chosen (e.g. choosing both `--all` and `--asin` or `--title`), no download option is chosen, or if both *ignore-podcasts* and *resolve-podcasts* options are selected together. It is now highlighted when the start date is after the end date in the parameters as well.
This commit is contained in:
parent
009a7e69ec
commit
6165e95f40
1 changed files with 17 additions and 9 deletions
|
@ -758,8 +758,10 @@ async def cli(session, api_client, **params):
|
|||
asins = params.get("asin")
|
||||
titles = params.get("title")
|
||||
if get_all and (asins or titles):
|
||||
logger.error("Do not mix *asin* or *title* option with *all* option.")
|
||||
click.Abort()
|
||||
raise click.BadOptionUsage(
|
||||
"--all",
|
||||
"`--all` can not be used together with `--asin` or `--title`"
|
||||
)
|
||||
|
||||
# what to download
|
||||
get_aax = params.get("aax")
|
||||
|
@ -780,8 +782,10 @@ async def cli(session, api_client, **params):
|
|||
if not any(
|
||||
[get_aax, get_aaxc, get_annotation, get_chapters, get_cover, get_pdf]
|
||||
):
|
||||
logger.error("Please select an option what you want download.")
|
||||
raise click.Abort()
|
||||
raise click.BadOptionUsage(
|
||||
"",
|
||||
"Please select an option what you want download."
|
||||
)
|
||||
|
||||
# additional options
|
||||
sim_jobs = params.get("jobs")
|
||||
|
@ -793,15 +797,19 @@ async def cli(session, api_client, **params):
|
|||
resolve_podcasts = params.get("resolve_podcasts")
|
||||
ignore_podcasts = params.get("ignore_podcasts")
|
||||
if all([resolve_podcasts, ignore_podcasts]):
|
||||
logger.error("Do not mix *ignore-podcasts* with *resolve-podcasts* option.")
|
||||
raise click.Abort()
|
||||
raise click.BadOptionUsage(
|
||||
"",
|
||||
"Do not mix *ignore-podcasts* with *resolve-podcasts* option."
|
||||
)
|
||||
bunch_size = session.params.get("bunch_size")
|
||||
|
||||
start_date = session.params.get("start_date")
|
||||
end_date = session.params.get("end_date")
|
||||
if all([start_date, end_date]) and start_date > end_date:
|
||||
logger.error("start date must be before or equal the end date")
|
||||
raise click.Abort()
|
||||
raise click.BadOptionUsage(
|
||||
"",
|
||||
"start date must be before or equal the end date"
|
||||
)
|
||||
|
||||
if start_date is not None:
|
||||
logger.info(
|
||||
|
@ -855,7 +863,7 @@ async def cli(session, api_client, **params):
|
|||
else:
|
||||
if not ignore_errors:
|
||||
logger.error(f"Asin {asin} not found in library.")
|
||||
click.Abort()
|
||||
raise click.Abort()
|
||||
logger.error(
|
||||
f"Skip asin {asin}: Not found in library"
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue