Add --wrap option for "ironic driver-properties"

This patch tries to add --wrap option to limit the
length of each line.
Default is disabled.

Change-Id: I3c1b2797cb481e6e826e88da70d87033ed2ba291
This commit is contained in:
xiexs 2015-11-20 01:01:58 -05:00
parent ada67331a9
commit e3183daa83
2 changed files with 41 additions and 6 deletions

View File

@ -72,6 +72,38 @@ class DriverShellTest(utils.BaseTestCase):
d_shell.do_driver_properties(client_mock, args)
client_mock.driver.properties.assert_called_once_with("driver_name")
@mock.patch('ironicclient.common.cliutils.print_dict')
def test_do_driver_properties_with_wrap_default(self, mock_print_dict):
client_mock = self.client_mock
client_mock.driver.properties.return_value = {
'foo': 'bar',
'baz': 'qux'}
args = mock.MagicMock()
args.driver_name = 'driver_name'
args.wrap = 0
d_shell.do_driver_properties(client_mock, args)
mock_print_dict.assert_called_with(
{'foo': 'bar', 'baz': 'qux'},
dict_value='Description',
wrap=0)
@mock.patch('ironicclient.common.cliutils.print_dict')
def test_do_driver_properties_with_wrap(self, mock_print_dict):
client_mock = self.client_mock
client_mock.driver.properties.return_value = {
'foo': 'bar',
'baz': 'qux'}
args = mock.MagicMock()
args.driver_name = 'driver_name'
args.wrap = 80
d_shell.do_driver_properties(client_mock, args)
mock_print_dict.assert_called_with(
{'foo': 'bar', 'baz': 'qux'},
dict_value='Description',
wrap=80)
def test_do_driver_show(self):
client_mock = self.client_mock
args = mock.MagicMock()

View File

@ -48,15 +48,18 @@ def do_driver_show(cc, args):
@cliutils.arg('driver_name', metavar='<driver>',
help="Name of the driver.")
@cliutils.arg('--wrap', dest='wrap', metavar='<integer>',
type=int, default=0,
help=('Wrap the output to a specified length. '
'Positive number can realize wrap functionality. '
'0 is default for disabled.'))
def do_driver_properties(cc, args):
"""Get properties of a driver."""
properties = cc.driver.properties(args.driver_name)
obj_list = []
for key, value in properties.items():
data = {'Property': key, 'Description': value}
obj_list.append(type('iface', (object,), data))
fields = ['Property', 'Description']
cliutils.print_list(obj_list, fields, mixed_case_fields=fields)
cliutils.print_dict(
properties,
wrap=args.wrap,
dict_value='Description')
@cliutils.arg('driver_name',