Climate client now shows the list of commands

HelpAction was removed from the parser to delay its
execution, otherwise the available commands were not
printed. I have also added a description for each
command to be displayed when running the 'help' command
in climate client.

Change-Id: Ic030a184f066e78daf556af8b26a02e79ef9c39a
Closes-Bug: #1311264
This commit is contained in:
Cristian A Sanchez 2014-04-25 11:31:46 -03:00
parent ea21932b97
commit 81577ffc3b
3 changed files with 28 additions and 2 deletions

View File

@ -93,7 +93,7 @@ class HelpAction(argparse.Action):
max_len = 0
app = self.default
parser.print_help(app.stdout)
app.stdout.write('\nCommands for API v%s:\n' % app.api_version)
app.stdout.write('\nCommands for API %s:\n' % app.api_version)
command_manager = app.command_manager
for name, ep in sorted(command_manager):
factory = ep.load()
@ -144,7 +144,7 @@ class ClimateShell(app.App):
dest='verbose_level',
const=0,
help='suppress output except warnings and errors')
parser.add_argument(
help_action = parser.add_argument(
'-h', '--help',
action=HelpAction,
nargs=0,
@ -156,6 +156,19 @@ class ClimateShell(app.App):
action='store_true',
help='show tracebacks on errors')
# Removes help action to defer its execution
self.deferred_help_action = help_action
parser._actions.remove(help_action)
del parser._option_string_actions['-h']
del parser._option_string_actions['--help']
parser.add_argument(
'-h', '--help',
action='store_true',
dest='deferred_help',
default=False,
help="Show this help message and exit",
)
# Global arguments
parser.add_argument(
'--os-reservation-api-version',
@ -299,6 +312,9 @@ class ClimateShell(app.App):
if help_command_pos > -1 and command_pos == -1:
argv[help_command_pos] = '--help'
if self.options.deferred_help:
self.deferred_help_action(self.parser, self.parser, None, None)
self.configure_logging()
self.interactive_mode = not remainder
self.initialize_app(remainder)

View File

@ -19,6 +19,7 @@ from climateclient import command
class ListHosts(command.ListCommand):
"""Print a list of host reservations."""
resource = 'host'
log = logging.getLogger(__name__ + '.ListHosts')
list_columns = ['id', 'hypervisor_hostname', 'vcpus', 'memory_mb',
@ -35,6 +36,7 @@ class ListHosts(command.ListCommand):
class ShowHost(command.ShowCommand):
"""Show host reservation details."""
resource = 'host'
json_indent = 4
# NOTE(sbauza): We can't find by name as there is currently no column
@ -44,6 +46,7 @@ class ShowHost(command.ShowCommand):
class CreateHost(command.CreateCommand):
"""Create a host reservation."""
resource = 'host'
json_indent = 4
log = logging.getLogger(__name__ + '.CreateHost')
@ -79,6 +82,7 @@ class CreateHost(command.CreateCommand):
class UpdateHost(command.UpdateCommand):
"""Update a host reservation."""
resource = 'host'
allow_names = False
log = logging.getLogger(__name__ + '.UpdateHost')
@ -108,6 +112,7 @@ class UpdateHost(command.UpdateCommand):
class DeleteHost(command.DeleteCommand):
"""Delete a host reservation."""
resource = 'host'
# NOTE(sbauza): We can't find by name as there is currently no column
# called 'name' but rather 'hypervisor_hostname'

View File

@ -23,6 +23,7 @@ from climateclient import exception
class ListLeases(command.ListCommand):
"""Print a list of leases."""
resource = 'lease'
log = logging.getLogger(__name__ + '.ListLeases')
list_columns = ['id', 'name', 'start_date', 'end_date']
@ -38,12 +39,14 @@ class ListLeases(command.ListCommand):
class ShowLease(command.ShowCommand):
"""Show details about the given lease."""
resource = 'lease'
json_indent = 4
log = logging.getLogger(__name__ + '.ShowLease')
class CreateLease(command.CreateCommand):
"""Create a lease."""
resource = 'lease'
log = logging.getLogger(__name__ + '.CreateLease')
default_start = datetime.datetime.utcnow()
@ -219,6 +222,7 @@ class CreateLease(command.CreateCommand):
class UpdateLease(command.UpdateCommand):
"""Update a lease."""
resource = 'lease'
log = logging.getLogger(__name__ + '.UpdateLease')
@ -260,5 +264,6 @@ class UpdateLease(command.UpdateCommand):
class DeleteLease(command.DeleteCommand):
"""Delete a lease."""
resource = 'lease'
log = logging.getLogger(__name__ + '.DeleteLease')