watson.console.command¶
-
class
watson.console.command.
Base
[source]¶ The base command that outlines the required structure for a console command.
Help is automatically invoked when the -h or –help option is used or when the command or namespace is not specified.
If a name attribute is not specified on the class then a snake_cased version of the name will be used in its place.
http://docs.python.org/dev/library/argparse.html#the-add-argument-method
Example:
# can be executed by `script.py my_namespace command` class MyNamespace(command.Base, ContainerAware): help = 'Top level namespace message' @arg() def command(self): '''Command specific help. ''' print('Run!') # with arguments from the function # can be executed by `script.py my_namespace command somevalue class MyNamespace(command.Base, ContainerAware): help = 'Top level namespace message' @arg() def command(self, value): '''Command specific help. Args: value: A value to pass ''' print('Run', value) # with options class MyNamespace(command.Base, ContainerAware): help = 'Top level namespace message' @arg('value', optional=True) def command(self, value): '''Command specific help. ''' print('Run!')