Permalink
Browse files

Merge "Add wrap option to nova credentials for humans"

  • Loading branch information...
Jenkins authored and openstack-gerrit committed Mar 11, 2013
2 parents b01ce12 + 21dca44 commit 2f2f4fcf2b80f7a6fd38bf093855ed3f89f8afd7
Showing with 10 additions and 4 deletions.
  1. +4 −1 novaclient/utils.py
  2. +5 −2 novaclient/v1_1/shell.py
  3. +1 −1 tests/test_shell.py
View
@@ -1,6 +1,7 @@
import os
import re
import sys
+import textwrap
import uuid
import prettytable
@@ -168,13 +169,15 @@ def print_list(objs, fields, formatters={}, sortby_index=0):
print(strutils.safe_encode(pt.get_string()))
-def print_dict(d, dict_property="Property"):
+def print_dict(d, dict_property="Property", wrap=0):
pt = prettytable.PrettyTable([dict_property, 'Value'], caching=False)
pt.align = 'l'
for k, v in d.iteritems():
# convert dict to str to check length
if isinstance(v, dict):
v = str(v)
+ if wrap > 0:
+ v = textwrap.fill(str(v), wrap)
# if value has a newline, add in multiple rows
# e.g. fault with stacktrace
if v and isinstance(v, basestring) and r'\n' in v:
View
@@ -2608,12 +2608,15 @@ def do_endpoints(cs, _args):
utils.print_dict(e['endpoints'][0], e['name'])
+@utils.arg('--wrap', dest='wrap', metavar='<integer>', default=64,
+ help='wrap PKI tokens to a specified length, or 0 to disable')
def do_credentials(cs, _args):
"""Show user credentials returned from auth"""
ensure_service_catalog_present(cs)
catalog = cs.client.service_catalog.catalog
- utils.print_dict(catalog['access']['user'], "User Credentials")
- utils.print_dict(catalog['access']['token'], "Token")
+ utils.print_dict(catalog['access']['user'], "User Credentials",
+ wrap=int(_args.wrap))
+ utils.print_dict(catalog['access']['token'], "Token", wrap=int(_args.wrap))
@utils.arg('server', metavar='<server>', help='Name or ID of server.')
View
@@ -102,7 +102,7 @@ def test_help_no_options(self):
def test_bash_completion(self):
stdout, stderr = self.shell('bash-completion')
# just check we have some output
- required = ['--matching help secgroup-delete-rule --priority']
+ required = ['--matching --wrap help secgroup-delete-rule --priority']
for r in required:
self.assertThat((stdout + stderr),
matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE))

0 comments on commit 2f2f4fc

Please sign in to comment.