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.
http://docs.python.org/dev/library/argparse.html#the-add-argument-method
Example:
# can be executed by `script.py mycommand` class MyCommand(BaseCommand): name = 'mycommand' def execute(self): return True # can be executed by `script.py mycommand -t something` class MyCommand(BaseCommand): name = 'mycommand' arguments = [ (['-t', '--test'], {'help': 'Do something with -t'}) ] def execute(self): return True if self.parsed_args.t else False # can be executed by `script.py mycommand something` class MyCommand(BaseCommand): name = 'mycommand' arguments = [ {'dest': 'argument1', 'help': 'This is the help for the argument'} ] def execute(self): return True if self.parsed_args.argument1 else False