Skip to content

Commit 34dc7ae

Browse files
author
Kevin McDonald
committed
Usability Tweeks
Removes global `--debug` option in favor of `--verbose` | `-v`. Removes global `--timings` option Adds more diagnostics whenever the verbose (-v) flag is set including the info that was displayed with `--timings` Converts to using lowercase name/value for tables instead of upper-case since lower-case is generally perferred for this tool at the moment Shows default values for many CLI options
1 parent 4015177 commit 34dc7ae

38 files changed

Lines changed: 142 additions & 116 deletions

SoftLayer/CLI/cdn/detail.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ def cli(env, account_id):
1717
manager = SoftLayer.CDNManager(env.client)
1818
account = manager.get_account(account_id)
1919

20-
table = formatting.KeyValueTable(['Name', 'Value'])
21-
table.align['Name'] = 'r'
22-
table.align['Value'] = 'l'
20+
table = formatting.KeyValueTable(['name', 'value'])
21+
table.align['name'] = 'r'
22+
table.align['value'] = 'l'
2323

2424
table.add_row(['id', account['id']])
2525
table.add_row(['account_name', account['cdnAccountName']])

SoftLayer/CLI/cdn/origin_add.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
@click.argument('content_url')
1515
@click.option('--type',
1616
help='The media type for this mapping (http, flash, wm, ...)',
17-
default='http')
17+
default='http',
18+
show_default=True)
1819
@click.option('--cname',
1920
help='An optional CNAME to attach to the mapping')
2021
@environment.pass_env

SoftLayer/CLI/config/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ def get_settings_from_client(client):
4242

4343
def config_table(settings):
4444
"""Returns a config table."""
45-
table = formatting.KeyValueTable(['Name', 'Value'])
46-
table.align['Name'] = 'r'
47-
table.align['Value'] = 'l'
45+
table = formatting.KeyValueTable(['name', 'value'])
46+
table.align['name'] = 'r'
47+
table.align['value'] = 'l'
4848
table.add_row(['Username', settings['username'] or 'not set'])
4949
table.add_row(['API Key', settings['api_key'] or 'not set'])
5050
table.add_row(['Endpoint URL', settings['endpoint_url'] or 'not set'])

SoftLayer/CLI/core.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
"""
88
from __future__ import print_function
99
import logging
10+
import os
1011
import sys
12+
import time
1113
import types
1214

1315
import click
@@ -16,10 +18,12 @@
1618
from SoftLayer.CLI import environment
1719
from SoftLayer.CLI import exceptions
1820
from SoftLayer.CLI import formatting
21+
from SoftLayer import consts
1922

2023
# pylint: disable=too-many-public-methods, broad-except, unused-argument
2124
# pylint: disable=redefined-builtin, super-init-not-called
2225

26+
START_TIME = time.time()
2327
DEBUG_LOGGING_MAP = {
2428
0: logging.CRITICAL,
2529
1: logging.WARNING,
@@ -73,57 +77,44 @@ def get_command(self, ctx, name):
7377
'auto_envvar_prefix': 'SLCLI'})
7478
@click.option('--format',
7579
default=DEFAULT_FORMAT,
80+
show_default=True,
7681
help="Output format",
7782
type=click.Choice(VALID_FORMATS))
7883
@click.option('--config', '-C',
7984
required=False,
8085
default=click.get_app_dir('softlayer', force_posix=True),
86+
show_default=True,
8187
help="Config file location",
8288
type=click.Path(resolve_path=True))
83-
@click.option('--debug',
84-
required=False,
85-
default=None,
86-
help="Sets the debug noise level",
87-
type=click.Choice(sorted([str(key) for key
88-
in DEBUG_LOGGING_MAP.keys()])))
8989
@click.option('--verbose', '-v',
90-
help="Sets the debug noise level",
90+
help="Sets the debug noise level, specify multiple times "
91+
"for more verbosity.",
9192
type=click.IntRange(0, 3, clamp=True),
9293
count=True)
93-
@click.option('--timings',
94-
required=False,
95-
is_flag=True,
96-
help="Time each API call and display after results")
9794
@click.option('--proxy',
9895
required=False,
9996
help="HTTP[S] proxy to be use to make API calls")
10097
@click.option('--really / --not-really', '-y',
10198
is_flag=True,
10299
required=False,
103100
help="Confirm all prompt actions")
104-
@click.option('--fixtures / --no-fixtures',
105-
envvar='SL_FIXTURES',
101+
@click.option('--demo / --no-demo',
106102
is_flag=True,
107103
required=False,
108-
help="Use fixtures instead of actually making API calls")
104+
help="Use demo data instead of actually making API calls")
109105
@click.version_option(prog_name="slcli (SoftLayer Command-line)")
110106
@environment.pass_env
111107
def cli(env,
112108
format='table',
113109
config=None,
114-
debug=0,
115110
verbose=0,
116111
proxy=None,
117112
really=False,
118-
fixtures=False,
113+
demo=False,
119114
**kwargs):
120115
"""Main click CLI entry-point."""
121116

122-
# Set logging level
123-
if debug is not None:
124-
verbose = int(debug)
125-
126-
if verbose:
117+
if verbose > 0:
127118
logger = logging.getLogger()
128119
logger.addHandler(logging.StreamHandler())
129120
logger.setLevel(DEBUG_LOGGING_MAP.get(verbose, logging.DEBUG))
@@ -134,7 +125,7 @@ def cli(env,
134125
env.format = format
135126
if env.client is None:
136127
# Environment can be passed in explicitly. This is used for testing
137-
if fixtures:
128+
if demo:
138129
client = SoftLayer.BaseClient(
139130
transport=SoftLayer.FixtureTransport(),
140131
auth=None,
@@ -147,23 +138,32 @@ def cli(env,
147138
)
148139
env.client = client
149140

141+
env.vars['_start'] = time.time()
150142
env.vars['_timings'] = SoftLayer.TimingTransport(env.client.transport)
151143
env.client.transport = env.vars['_timings']
152144

153145

154146
@cli.resultcallback()
155147
@environment.pass_env
156-
def output_result(env, timings=False, *args, **kwargs):
157-
"""Outputs the results returned by the CLI and also outputs timings."""
148+
def output_diagnostics(env, verbose=0, **kwargs):
149+
"""Output diagnostic information."""
150+
151+
if verbose > 0:
152+
diagnostic_table = formatting.Table(['name', 'value'])
153+
diagnostic_table.add_row(['execution_time', time.time() - START_TIME])
158154

159-
if timings and env.vars.get('_timings'):
160-
timing_table = formatting.Table(['service', 'method', 'time'])
155+
api_call_value = []
156+
for call, _, duration in env.vars['_timings'].get_last_calls():
157+
api_call_value.append(
158+
"%s::%s (%fs)" % (call.service, call.method, duration))
161159

162-
calls = env.vars['_timings'].get_last_calls()
163-
for call, _, duration in calls:
164-
timing_table.add_row([call.service, call.method, duration])
160+
diagnostic_table.add_row(['api_calls', api_call_value])
161+
diagnostic_table.add_row(['version', consts.USER_AGENT])
162+
diagnostic_table.add_row(['python_version', sys.version])
163+
diagnostic_table.add_row(['library_location',
164+
os.path.dirname(SoftLayer.__file__)])
165165

166-
env.err(env.fmt(timing_table))
166+
env.err(env.fmt(diagnostic_table))
167167

168168

169169
def main(reraise_exceptions=False, **kwargs):

SoftLayer/CLI/dns/record_add.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
@click.option('--ttl',
1818
type=click.INT,
1919
default=7200,
20+
show_default=True,
2021
help='TTL value in seconds, such as 86400')
2122
@environment.pass_env
2223
def cli(env, zone, record, type, data, ttl):

SoftLayer/CLI/formatting.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,9 @@ def iter_to_table(value):
371371
def _format_dict(result):
372372
"""Format dictionary responses into key-value table."""
373373

374-
table = KeyValueTable(['Name', 'Value'])
375-
table.align['Name'] = 'r'
376-
table.align['Value'] = 'l'
374+
table = KeyValueTable(['name', 'value'])
375+
table.align['name'] = 'r'
376+
table.align['value'] = 'l'
377377

378378
for key, value in result.items():
379379
value = iter_to_table(value)
@@ -391,7 +391,7 @@ def _format_list(result):
391391
if isinstance(result[0], dict):
392392
return _format_list_objects(result)
393393

394-
table = Table(["Value"])
394+
table = Table(['value'])
395395
for item in result:
396396
table.add_row([iter_to_table(item)])
397397
return table

SoftLayer/CLI/image/detail.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ def cli(env, identifier):
2828
if child.get('datacenter'):
2929
datacenters.append(utils.lookup(child, 'datacenter', 'name'))
3030

31-
table = formatting.KeyValueTable(['Name', 'Value'])
32-
table.align['Name'] = 'r'
33-
table.align['Value'] = 'l'
31+
table = formatting.KeyValueTable(['name', 'value'])
32+
table.align['name'] = 'r'
33+
table.align['value'] = 'l'
3434

3535
table.add_row(['id', image['id']])
3636
table.add_row(['global_identifier',

SoftLayer/CLI/image/import.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
@click.command()
1313
@click.argument('name')
1414
@click.argument('uri')
15-
@click.option('--note', default="",
15+
@click.option('--note',
16+
default="",
1617
help="The note to be applied to the imported template")
17-
@click.option('--os-code', default="",
18+
@click.option('--os-code',
19+
default="",
1820
help="The referenceCode of the operating system software"
1921
" description for the imported VHD")
2022
@environment.pass_env

SoftLayer/CLI/iscsi/detail.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ def cli(env, identifier, password):
2525
result = iscsi_mgr.get_iscsi(iscsi_id)
2626
result = utils.NestedDict(result)
2727

28-
table = formatting.KeyValueTable(['Name', 'Value'])
29-
table.align['Name'] = 'r'
30-
table.align['Value'] = 'l'
28+
table = formatting.KeyValueTable(['name', 'value'])
29+
table.align['name'] = 'r'
30+
table.align['value'] = 'l'
3131

3232
table.add_row(['id', result['id']])
3333
table.add_row(['serviceResourceName', result['serviceResourceName']])

SoftLayer/CLI/loadbal/detail.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ def cli(env, identifier):
2020

2121
load_balancer = mgr.get_local_lb(loadbal_id)
2222

23-
table = formatting.KeyValueTable(['Name', 'Value'])
24-
table.align['Name'] = 'l'
25-
table.align['Value'] = 'l'
23+
table = formatting.KeyValueTable(['name', 'value'])
24+
table.align['name'] = 'l'
25+
table.align['value'] = 'l'
2626
table.add_row(['General properties', '----------'])
2727
table.add_row([' ID', 'local:%s' % load_balancer['id']])
2828
table.add_row([' IP Address', load_balancer['ipAddress']['ipAddress']])

0 commit comments

Comments
 (0)