Source code for cloudmesh_client.shell.command

import inspect
import textwrap
import shlex

from docopt import docopt


[docs]class PluginCommand(object): pass
[docs]class CloudPluginCommand(object): pass
[docs]class ShellPluginCommand(object): pass
[docs]class HPCPluginCommand(object): pass
[docs]class CometPluginCommand(object): pass
# noinspection PySingleQuotedDocstring
[docs]def command(func): ''' A decorator to create a function with docopt arguments. It also generates a help function @command def do_myfunc(self, args): """ docopts text """ pass will create def do_myfunc(self, args, arguments): """ docopts text """ ... def help_myfunc(self, args, arguments): ... prints the docopt text ... :param func: the function for the decorator ''' classname = inspect.getouterframes(inspect.currentframe())[1][3] name = func.__name__ help_name = name.replace("do_", "help_") doc = textwrap.dedent(func.__doc__) def new(instance, args): # instance.new.__doc__ = doc try: argv = shlex.split(args) arguments = docopt(doc, help=True, argv=argv) func(instance, args, arguments) except SystemExit as e: if args not in ('-h', '--help'): print("Could not execute the command.") print(e) print(doc) new.__doc__ = doc return new