Add bash-completion command support

Implement a helper command 'mistral bash-completion' to generate available
commands and options supported by mistral.

Change-Id: Id0e52daf4ee3f7c1ba9fefaa4f103bd74e66d97d
Partically Implements: blueprint bash-completion-script-optimization
This commit is contained in:
LingxianKong 2015-05-18 09:24:09 +08:00
parent 63a41d657d
commit 1e79ff5471

View File

@ -31,6 +31,7 @@ import mistralclient.commands.v2.workflows
from mistralclient.openstack.common import cliutils as c
from cliff import app
from cliff import command
from cliff import commandmanager
import argparse
@ -80,6 +81,22 @@ class HelpAction(argparse.Action):
sys.exit(0)
class BashCompletionCommand(command.Command):
"""Prints all of the commands and options for bash-completion."""
def take_action(self, parsed_args):
commands = set()
options = set()
for option, _action in self.app.parser._option_string_actions.items():
options.add(option)
for command_name, _cmd in self.app.command_manager:
commands.add(command_name)
print(' '.join(commands | options))
class MistralShell(app.App):
def __init__(self):
@ -257,6 +274,7 @@ class MistralShell(app.App):
@staticmethod
def _get_commands_v2():
return {
'bash-completion': BashCompletionCommand,
'workbook-list': mistralclient.commands.v2.workbooks.List,
'workbook-get': mistralclient.commands.v2.workbooks.Get,
'workbook-create': mistralclient.commands.v2.workbooks.Create,