cli errors leverage click output and suggest --help

This commit is contained in:
Chris Caron 2024-09-02 12:54:53 -04:00
parent 1a2eecc448
commit 0d19db862d

View File

@ -468,27 +468,30 @@ def main(ctx, body, title, config, attach, urls, notification_type, theme, tag,
# Simple Error Checking # Simple Error Checking
notification_type = notification_type.strip().lower() notification_type = notification_type.strip().lower()
if notification_type not in NOTIFY_TYPES: if notification_type not in NOTIFY_TYPES:
logger.error( click.echo(
'The --notification-type (-n) value of {} is not supported.' 'The --notification-type (-n) value of {} is not supported.'
.format(notification_type)) .format(notification_type))
click.echo("Try 'apprise --help' for more information.")
# 2 is the same exit code returned by Click if there is a parameter # 2 is the same exit code returned by Click if there is a parameter
# issue. For consistency, we also return a 2 # issue. For consistency, we also return a 2
ctx.exit(2) ctx.exit(2)
input_format = input_format.strip().lower() input_format = input_format.strip().lower()
if input_format not in NOTIFY_FORMATS: if input_format not in NOTIFY_FORMATS:
logger.error( click.echo(
'The --input-format (-i) value of {} is not supported.' 'The --input-format (-i) value of {} is not supported.'
.format(input_format)) .format(input_format))
click.echo("Try 'apprise --help' for more information.")
# 2 is the same exit code returned by Click if there is a parameter # 2 is the same exit code returned by Click if there is a parameter
# issue. For consistency, we also return a 2 # issue. For consistency, we also return a 2
ctx.exit(2) ctx.exit(2)
storage_mode = storage_mode.strip().lower() storage_mode = storage_mode.strip().lower()
if storage_mode not in PERSISTENT_STORE_MODES: if storage_mode not in PERSISTENT_STORE_MODES:
logger.error( click.echo(
'The --storage-mode (-SM) value of {} is not supported.' 'The --storage-mode (-SM) value of {} is not supported.'
.format(storage_mode)) .format(storage_mode))
click.echo("Try 'apprise --help' for more information.")
# 2 is the same exit code returned by Click if there is a parameter # 2 is the same exit code returned by Click if there is a parameter
# issue. For consistency, we also return a 2 # issue. For consistency, we also return a 2
ctx.exit(2) ctx.exit(2)
@ -500,9 +503,10 @@ def main(ctx, body, title, config, attach, urls, notification_type, theme, tag,
if exists(path_decode(path))] if exists(path_decode(path))]
if storage_uid_length < 2: if storage_uid_length < 2:
logger.error( click.echo(
'The --storage-uid-length (-SUL) value can not be lower ' 'The --storage-uid-length (-SUL) value can not be lower '
'then two (2).') 'then two (2).')
click.echo("Try 'apprise --help' for more information.")
# 2 is the same exit code returned by Click if there is a # 2 is the same exit code returned by Click if there is a
# parameter issue. For consistency, we also return a 2 # parameter issue. For consistency, we also return a 2
@ -683,9 +687,10 @@ def main(ctx, body, title, config, attach, urls, notification_type, theme, tag,
asset=asset, recursion=recursion_depth)) asset=asset, recursion=recursion_depth))
if not dry_run and not (a or storage_action): if not dry_run and not (a or storage_action):
logger.error( click.echo(
'You must specify at least one server URL or populated ' 'You must specify at least one server URL or populated '
'configuration file.') 'configuration file.')
click.echo("Try 'apprise --help' for more information.")
ctx.exit(1) ctx.exit(1)
# each --tag entry comprises of a comma separated 'and' list # each --tag entry comprises of a comma separated 'and' list
@ -700,9 +705,10 @@ def main(ctx, body, title, config, attach, urls, notification_type, theme, tag,
# - urls are now to be interpreted as best matching namespaces # - urls are now to be interpreted as best matching namespaces
# #
if storage_prune_days < 0: if storage_prune_days < 0:
logger.error( click.echo(
'The --storage-prune-days (-SPD) value can not be lower ' 'The --storage-prune-days (-SPD) value can not be lower '
'then zero (0).') 'then zero (0).')
click.echo("Try 'apprise --help' for more information.")
# 2 is the same exit code returned by Click if there is a # 2 is the same exit code returned by Click if there is a
# parameter issue. For consistency, we also return a 2 # parameter issue. For consistency, we also return a 2