diff options
Diffstat (limited to 'libs/apprise/cli.py')
-rw-r--r-- | libs/apprise/cli.py | 69 |
1 files changed, 56 insertions, 13 deletions
diff --git a/libs/apprise/cli.py b/libs/apprise/cli.py index e43f88a23..57e964a72 100644 --- a/libs/apprise/cli.py +++ b/libs/apprise/cli.py @@ -99,6 +99,9 @@ def print_version_msg(): @click.option('--config', '-c', default=None, type=str, multiple=True, metavar='CONFIG_URL', help='Specify one or more configuration locations.') [email protected]('--attach', '-a', default=None, type=str, multiple=True, + metavar='ATTACHMENT_URL', + help='Specify one or more configuration locations.') @click.option('--notification-type', '-n', default=NotifyType.INFO, type=str, metavar='TYPE', help='Specify the message type (default=info). Possible values' @@ -111,13 +114,17 @@ def print_version_msg(): 'which services to notify. Use multiple --tag (-g) entries to ' '"OR" the tags together and comma separated to "AND" them. ' 'If no tags are specified then all services are notified.') [email protected]('-v', '--verbose', count=True) [email protected]('-V', '--version', is_flag=True, [email protected]('--dry-run', '-d', is_flag=True, + help='Perform a trial run but only prints the notification ' + 'services to-be triggered to stdout. Notifications are never ' + 'sent using this mode.') [email protected]('--verbose', '-v', count=True) [email protected]('--version', '-V', is_flag=True, help='Display the apprise version and exit.') @click.argument('urls', nargs=-1, metavar='SERVER_URL [SERVER_URL2 [SERVER_URL3]]',) -def main(body, title, config, urls, notification_type, theme, tag, verbose, - version): +def main(body, title, config, attach, urls, notification_type, theme, tag, + dry_run, verbose, version): """ Send a notification to all of the specified servers identified by their URLs the content provided within the title, body and notification-type. @@ -184,16 +191,52 @@ def main(body, title, config, urls, notification_type, theme, tag, verbose, print_help_msg(main) sys.exit(1) - if body is None: - # if no body was specified, then read from STDIN - body = click.get_text_stream('stdin').read() - # each --tag entry comprises of a comma separated 'and' list # we or each of of the --tag and sets specified. tags = None if not tag else [parse_list(t) for t in tag] - # now print it out - if a.notify( - body=body, title=title, notify_type=notification_type, tag=tags): - sys.exit(0) - sys.exit(1) + if not dry_run: + if body is None: + logger.trace('No --body (-b) specified; reading from stdin') + # if no body was specified, then read from STDIN + body = click.get_text_stream('stdin').read() + + # now print it out + result = a.notify( + body=body, title=title, notify_type=notification_type, tag=tags, + attach=attach) + else: + # Number of rows to assume in the terminal. In future, maybe this can + # be detected and made dynamic. The actual row count is 80, but 5 + # characters are already reserved for the counter on the left + rows = 75 + + # Initialize our URL response; This is populated within the for/loop + # below; but plays a factor at the end when we need to determine if + # we iterated at least once in the loop. + url = None + + for idx, server in enumerate(a.find(tag=tags)): + url = server.url(privacy=True) + click.echo("{: 3d}. {}".format( + idx + 1, + url if len(url) <= rows else '{}...'.format(url[:rows - 3]))) + if server.tags: + click.echo("{} - {}".format(' ' * 5, ', '.join(server.tags))) + + # Initialize a default response of nothing matched, otherwise + # if we matched at least one entry, we can return True + result = None if url is None else True + + if result is None: + # There were no notifications set. This is a result of just having + # empty configuration files and/or being to restrictive when filtering + # by specific tag(s) + sys.exit(2) + + elif result is False: + # At least 1 notification service failed to send + sys.exit(1) + + # else: We're good! + sys.exit(0) |