Skip to content

Commit daacd2c

Browse files
committed
Output format passed using obj not ctx
1 parent 4774124 commit daacd2c

13 files changed

Lines changed: 35 additions & 36 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Profiles can be used to easily switch between different configuration settings.
3333
| timezone | timezone | n/a | n/a | Europe/London |
3434
| SSL verify | sslverify | ``REQUESTS_CA_BUNDLE`` | n/a | verify SSL certificates |
3535
| timeout | timeout | n/a | n/a | 5s TCP connection timeout |
36-
| output | output | n/a | ``--output OUTPUT`` | simple |
36+
| output | output | n/a | ``--output-format OUTPUT`` | simple |
3737
| color | color | ``CLICOLOR`` | ``--color``, ``--no-color`` | color on |
3838
| debug | debug | ``DEBUG`` | ``--debug`` | no debug |
3939

alertaclient/cli.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ def get_command(self, ctx, name):
4141
@click.option('--config-file', metavar='<FILE>', help='Configuration file.')
4242
@click.option('--profile', metavar='<PROFILE>', help='Configuration profile.')
4343
@click.option('--endpoint-url', metavar='<URL>', help='API endpoint URL.')
44-
@click.option('--output-format', metavar='<FORMAT>', default='psql', help='Output format. eg. simple, grid, psql, presto, rst')
44+
@click.option('--output', 'output', metavar='<FORMAT>', help='Output format. eg. simple, grid, psql, presto, rst')
4545
@click.option('--color/--no-color', help='Color-coded output based on severity.')
4646
@click.option('--debug', is_flag=True, help='Debug mode.')
4747
@click.pass_context
48-
def cli(ctx, config_file, profile, endpoint_url, output_format, color, debug):
48+
def cli(ctx, config_file, profile, endpoint_url, output, color, debug):
4949
"""
5050
Alerta client unified command-line tool.
5151
"""
@@ -54,6 +54,8 @@ def cli(ctx, config_file, profile, endpoint_url, output_format, color, debug):
5454

5555
ctx.obj = dict()
5656
ctx.obj['timezone'] = config.options['timezone']
57+
ctx.obj['output'] = output or config.options['output']
58+
ctx.obj['color'] = color or config.options['color']
5759

5860
endpoint = endpoint_url or config.options['endpoint']
5961

alertaclient/commands/cmd_blackouts.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
@click.command('blackouts', short_help='List alert suppressions')
99
@click.option('--purge', is_flag=True, help='Delete all expired blackouts')
1010
@click.pass_obj
11-
@click.pass_context
12-
def cli(ctx, obj, purge):
11+
def cli(obj, purge):
1312
"""List alert suppressions."""
1413
client = obj['client']
1514
timezone = obj['timezone']
@@ -19,7 +18,7 @@ def cli(ctx, obj, purge):
1918
'duration': 'DURATION', 'status': 'STATUS', 'remaining': 'REMAINING', 'customer': 'CUSTOMER'
2019
}
2120
blackouts = client.get_blackouts()
22-
click.echo(tabulate([b.serialize(timezone) for b in blackouts], headers=headers, tablefmt=ctx.parent.params['output_format']))
21+
click.echo(tabulate([b.serialize(timezone) for b in blackouts], headers=headers, tablefmt=obj['output']))
2322

2423
expired = [b for b in blackouts if b.status == 'expired']
2524
if purge:

alertaclient/commands/cmd_customers.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77

88
@click.command('customers', short_help='List customer lookups')
99
@click.pass_obj
10-
@click.pass_context
11-
def cli(ctx, obj):
10+
def cli(obj):
1211
"""List customer lookups."""
1312
client = obj['client']
1413
headers = {'id': 'ID', 'customer': 'CUSTOMER', 'match': 'GROUP'}
15-
click.echo(tabulate([c.serialize() for c in client.get_customers()], headers=headers, tablefmt=ctx.parent.params['output_format']))
14+
click.echo(tabulate([c.serialize() for c in client.get_customers()], headers=headers, tablefmt=obj['output']))

alertaclient/commands/cmd_heartbeats.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
@click.command('heartbeats', short_help='List heartbeats')
88
@click.option('--purge', is_flag=True, help='Delete stale heartbeats')
99
@click.pass_obj
10-
@click.pass_context
11-
def cli(ctx, obj, purge):
10+
def cli(obj, purge):
1211
"""List heartbeats."""
1312
client = obj['client']
1413
timezone = obj['timezone']
@@ -17,7 +16,7 @@ def cli(ctx, obj, purge):
1716
'receiveTime': 'RECEIVED', 'latency': 'LATENCY', 'timeout': 'TIMEOUT', 'since': 'SINCE', 'status': 'STATUS'
1817
}
1918
heartbeats = client.get_heartbeats()
20-
click.echo(tabulate([h.serialize(timezone) for h in heartbeats], headers=headers, tablefmt=ctx.parent.params['output_format']))
19+
click.echo(tabulate([h.serialize(timezone) for h in heartbeats], headers=headers, tablefmt=obj['output']))
2120

2221
expired = [hb for hb in heartbeats if hb.status == 'expired']
2322
if purge:

alertaclient/commands/cmd_history.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
@click.option('--ids', '-i', metavar='UUID', multiple=True, help='List of alert IDs (can use short 8-char id)')
1010
@click.option('--filter', '-f', 'filters', metavar='FILTER', multiple=True, help='KEY=VALUE eg. serverity=warning resource=web')
1111
@click.pass_obj
12-
@click.pass_context
13-
def cli(ctx, obj, ids, filters):
12+
def cli(obj, ids, filters):
1413
"""Show status and severity changes for alerts."""
1514
client = obj['client']
1615
timezone = obj['timezone']
@@ -24,4 +23,4 @@ def cli(ctx, obj, ids, filters):
2423
'type': 'TYPE', 'customer': 'CUSTOMER', 'environment': 'ENVIRONMENT', 'service': 'SERVICE',
2524
'resource': 'RESOURCE', 'group': 'GROUP', 'event': 'EVENT', 'value': 'VALUE', 'text': 'TEXT'}
2625
click.echo(
27-
tabulate([a.serialize(timezone) for a in alerts], headers=headers, tablefmt=ctx.parent.params['output_format']))
26+
tabulate([a.serialize(timezone) for a in alerts], headers=headers, tablefmt=obj['output']))

alertaclient/commands/cmd_keys.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66

77
@click.command('customers', short_help='List API keys')
88
@click.pass_obj
9-
@click.pass_context
10-
def cli(ctx, obj):
9+
def cli(obj):
1110
"""List API keys."""
1211
client = obj['client']
1312
timezone = obj['timezone']
1413
headers = {
1514
'id': 'ID', 'key': 'API KEY', 'user': 'USER', 'scopes': 'SCOPES', 'text': 'TEXT',
1615
'expireTime': 'EXPIRES', 'count': 'COUNT', 'lastUsedTime': 'LAST USED', 'customer': 'CUSTOMER'
1716
}
18-
click.echo(tabulate([k.serialize(timezone) for k in client.get_keys()], headers=headers, tablefmt=ctx.parent.params['output_format']))
17+
click.echo(tabulate([k.serialize(timezone) for k in client.get_keys()], headers=headers, tablefmt=obj['output']))

alertaclient/commands/cmd_perms.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77

88
@click.command('perms', short_help='List role-permission lookups')
99
@click.pass_obj
10-
@click.pass_context
11-
def cli(ctx, obj):
10+
def cli(obj):
1211
"""List permissions."""
1312
client = obj['client']
1413
headers = {'id': 'ID', 'scopes': 'SCOPES', 'match': 'ROLE'}
15-
click.echo(tabulate([p.serialize() for p in client.get_perms()], headers=headers, tablefmt=ctx.parent.params['output_format']))
14+
click.echo(tabulate([p.serialize() for p in client.get_perms()], headers=headers, tablefmt=obj['output']))

alertaclient/commands/cmd_query.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
@click.option('--filter', '-f', 'filters', metavar='FILTER', multiple=True, help='KEY=VALUE eg. serverity=warning resource=web')
2020
@click.option('--compact/--no-compact', help='Show alert details')
2121
@click.pass_obj
22-
@click.pass_context
23-
def cli(ctx, obj, ids, filters, compact):
22+
def cli(obj, ids, filters, compact):
2423
"""Query for alerts based on search filter criteria."""
2524
client = obj['client']
2625
timezone = obj['timezone']
@@ -35,7 +34,7 @@ def cli(ctx, obj, ids, filters, compact):
3534
headers = {'id': 'ID', 'lastReceiveTime': 'LAST RECEIVED', 'severity': 'SEVERITY', 'duplicateCount': 'DUPL',
3635
'customer': 'CUSTOMER', 'environment': 'ENVIRONMENT', 'service': 'SERVICE', 'resource': 'RESOURCE',
3736
'group': 'GROUP', 'event': 'EVENT', 'value': 'VALUE'}
38-
click.echo(tabulate([a.serialize('summary', timezone) for a in alerts], headers=headers, tablefmt=ctx.parent.params['output_format']))
37+
click.echo(tabulate([a.serialize('summary', timezone) for a in alerts], headers=headers, tablefmt=obj['output']))
3938
else:
4039
for alert in alerts:
4140
color = COLOR_MAP.get(alert.severity, {'fg': 'white'})

alertaclient/commands/cmd_raw.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
@click.option('--ids', '-i', metavar='UUID', multiple=True, help='List of alert IDs (can use short 8-char id)')
1010
@click.option('--filter', '-f', 'filters', metavar='FILTER', multiple=True, help='KEY=VALUE eg. serverity=warning resource=web')
1111
@click.pass_obj
12-
@click.pass_context
13-
def cli(ctx, obj, ids, filters):
12+
def cli(obj, ids, filters):
1413
client = obj['client']
1514
"""Show raw data for alerts."""
1615
if ids:
@@ -21,4 +20,4 @@ def cli(ctx, obj, ids, filters):
2120

2221
headers = {'id': 'ID', 'rawData': 'RAW DATA'}
2322
click.echo(
24-
tabulate([{'id': a.id, 'rawData': a.raw_data} for a in alerts], headers=headers, tablefmt=ctx.parent.params['output_format']))
23+
tabulate([{'id': a.id, 'rawData': a.raw_data} for a in alerts], headers=headers, tablefmt=obj['output']))

0 commit comments

Comments
 (0)