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:
@@ -31,6 +31,7 @@ import mistralclient.commands.v2.workflows
|
|||||||
from mistralclient.openstack.common import cliutils as c
|
from mistralclient.openstack.common import cliutils as c
|
||||||
|
|
||||||
from cliff import app
|
from cliff import app
|
||||||
|
from cliff import command
|
||||||
from cliff import commandmanager
|
from cliff import commandmanager
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
@@ -80,6 +81,22 @@ class HelpAction(argparse.Action):
|
|||||||
sys.exit(0)
|
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):
|
class MistralShell(app.App):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -257,6 +274,7 @@ class MistralShell(app.App):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_commands_v2():
|
def _get_commands_v2():
|
||||||
return {
|
return {
|
||||||
|
'bash-completion': BashCompletionCommand,
|
||||||
'workbook-list': mistralclient.commands.v2.workbooks.List,
|
'workbook-list': mistralclient.commands.v2.workbooks.List,
|
||||||
'workbook-get': mistralclient.commands.v2.workbooks.Get,
|
'workbook-get': mistralclient.commands.v2.workbooks.Get,
|
||||||
'workbook-create': mistralclient.commands.v2.workbooks.Create,
|
'workbook-create': mistralclient.commands.v2.workbooks.Create,
|
||||||
|
Reference in New Issue
Block a user