Skip to content

Commit daea389

Browse files
committed
Update help text and minor usability fixes
1 parent ca1d70f commit daea389

35 files changed

Lines changed: 78 additions & 77 deletions

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ And to switch to development configuration settings when required use the ``--pr
7474
Usage
7575
-----
7676

77-
$ alerta help
77+
$ alerta
7878
Usage: alerta [OPTIONS] COMMAND [ARGS]...
7979

8080
Alerta client unified command-line tool.
@@ -115,6 +115,7 @@ Usage
115115
token display current auth token
116116
unack un-acknowledge alert
117117
untag untag alert
118+
update update alert attributes
118119
uptime display server uptime
119120
user update user
120121
users list users

alertaclient/auth.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
import os
3+
import click
34

45
from netrc import netrc
56

@@ -33,9 +34,12 @@ def save_token(endpoint, username, token):
3334

3435
def clear_token(endpoint):
3536
info = netrc(NETRC_FILE)
36-
del info.hosts[machine(endpoint)]
37-
with open(NETRC_FILE, 'w') as f:
38-
f.write(dump_netrc(info))
37+
try:
38+
del info.hosts[machine(endpoint)]
39+
with open(NETRC_FILE, 'w') as f:
40+
f.write(dump_netrc(info))
41+
except KeyError as e:
42+
raise click.UsageError('No credentials for user found.')
3943

4044

4145
# See https://bugs.python.org/issue30806

alertaclient/cli.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@ def cli(ctx, config_file, profile, endpoint_url, output_format, color, debug):
5555
ctx.obj = dict()
5656
ctx.obj['timezone'] = config.options['timezone']
5757

58+
endpoint = endpoint_url or config.options['endpoint']
59+
5860
ctx.obj['client'] = Client(
59-
endpoint=endpoint_url or config.options['endpoint'],
61+
endpoint=endpoint,
6062
key=config.options['key'],
61-
token=get_token(endpoint_url),
63+
token=get_token(endpoint),
6264
timeout=config.options['timeout'],
6365
ssl_verify=config.options['sslverify'],
6466
debug=debug or config.options['debug']

alertaclient/commands/cmd_ack.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
from alertaclient.utils import build_query
44

55

6-
@click.command('ack', short_help='acknowledge alert')
7-
@click.option('--ids', '-i', multiple=True, help='List of alert IDs (can use short 8-char id)')
6+
@click.command('ack', short_help='Acknowledge alerts')
7+
@click.option('--ids', '-i', metavar='UUID', multiple=True, help='List of alert IDs (can use short 8-char id)')
88
@click.option('--filter', '-f', 'filters', metavar='FILTER', multiple=True, help='KEY=VALUE eg. serverity=warning resource=web')
9-
@click.option('--text')
9+
@click.option('--text', help='Message associated with status change')
1010
@click.pass_obj
1111
def cli(obj, ids, filters, text):
1212
"""Set alert status to 'ack'."""

alertaclient/commands/cmd_blackout.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
import click
44

55

6-
@click.command('blackout', short_help='suppress alerts')
7-
@click.option('--environment', '-E')
8-
@click.option('--service', '-S', multiple=True)
9-
@click.option('--resource', '-r')
10-
@click.option('--event', '-e')
11-
@click.option('--group', '-g')
12-
@click.option('--tag', '-T', 'tags', multiple=True)
13-
@click.option('--start')
14-
@click.option('--duration', default=86400) # TODO ??
15-
@click.option('--delete', '-D', help='delete blackout using ID')
6+
@click.command('blackout', short_help='Suppress alerts')
7+
@click.option('--environment', '-E', metavar='ENVIRONMENT')
8+
@click.option('--service', '-S', metavar='SERVICE', multiple=True)
9+
@click.option('--resource', '-r', metavar='RESOURCE')
10+
@click.option('--event', '-e', metavar='EVENT')
11+
@click.option('--group', '-g', metavar='GROUP')
12+
@click.option('--tag', '-T', 'tags', metavar='TAG', multiple=True)
13+
@click.option('--start', metavar='DATETIME')
14+
@click.option('--duration', metavar='EXPIRES')
15+
@click.option('--delete', '-D', help='Delete blackout using ID')
1616
@click.pass_obj
1717
def cli(obj, environment, service, resource, event, group, tags, start, duration, delete):
1818
"""Suppress alerts for specified duration based on alert attributes."""

alertaclient/commands/cmd_blackouts.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
from tabulate import tabulate
66

77

8-
@click.command('blackouts', short_help='list alert suppressions')
9-
@click.option('--purge', is_flag=True)
8+
@click.command('blackouts', short_help='List alert suppressions')
9+
@click.option('--purge', is_flag=True, help='Delete all expired blackouts')
1010
@click.pass_obj
1111
@click.pass_context
1212
def cli(ctx, obj, purge):

alertaclient/commands/cmd_close.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from alertaclient.utils import build_query
44

55

6-
@click.command('ack', short_help='close alert')
7-
@click.option('--ids', '-i', multiple=True, help='List of alert IDs (can use short 8-char id)')
6+
@click.command('ack', short_help='Close alerts')
7+
@click.option('--ids', '-i', metavar='UUID', multiple=True, help='List of alert IDs (can use short 8-char id)')
88
@click.option('--filter', '-f', 'filters', metavar='FILTER', multiple=True, help='KEY=VALUE eg. serverity=warning resource=web')
99
@click.option('--text')
1010
@click.pass_obj

alertaclient/commands/cmd_customer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import click
44

55

6-
@click.command('customer', short_help='add customer lookup')
6+
@click.command('customer', short_help='Add customer lookup')
77
@click.option('--customer', help='customer name')
88
@click.option('--org', '--group', '--domain', '--role', 'match', help='used to lookup customer')
99
@click.option('--delete', '-D', metavar='ID', help='delete customer')

alertaclient/commands/cmd_customers.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
from tabulate import tabulate
66

77

8-
@click.command('customers', short_help='list customer lookups')
8+
@click.command('customers', short_help='List customer lookups')
99
@click.pass_obj
1010
@click.pass_context
11-
def cli(obj, client):
11+
def cli(ctx, obj):
1212
"""List customer lookups."""
1313
client = obj['client']
14-
timezone = obj['timezone']
1514
headers = {'id': 'ID', 'customer': 'CUSTOMER', 'match': 'GROUP'}
16-
click.echo(tabulate([c.serialize(timezone) for c in client.get_customers()], headers=headers, tablefmt=ctx.parent.params['output_format']))
15+
click.echo(tabulate([c.serialize() for c in client.get_customers()], headers=headers, tablefmt=ctx.parent.params['output_format']))

alertaclient/commands/cmd_delete.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from alertaclient.utils import build_query
44

55

6-
@click.command('delete', short_help='delete alert')
7-
@click.option('--ids', '-i', multiple=True, help='List of alert IDs (can use short 8-char id)')
6+
@click.command('delete', short_help='Delete alerts')
7+
@click.option('--ids', '-i', metavar='UUID', multiple=True, help='List of alert IDs (can use short 8-char id)')
88
@click.option('--filter', '-f', 'filters', metavar='FILTER', multiple=True, help='KEY=VALUE eg. serverity=warning resource=web')
99
@click.pass_obj
1010
def cli(obj, ids, filters):

0 commit comments

Comments
 (0)