Base class for writing simple interactive command loop environments.
CommandLoop provides a base class for writing simple interactive user
environments. It is designed around sub-classing, has a simple command
parser, and is trivial to initialize.
Here is a trivial little environment written using CommandLoop:
import cmdloop
class Hello(cmdloop.CommandLoop):
PS1='hello>'
@cmdloop.aliases('hello', 'hi', 'hola')
@cmdloop.shorthelp('say hello')
@cmdloop.usage('hello TARGET')
def helloCmd(self, flags, args):
'''
Say hello to TARGET, which defaults to 'world'
'''
if flags or len(args) > 1:
raise InvalidArguments
if args:
target = args[0]
else:
target = self.default_target
print >> self.OUT, 'Hello %s ...