import codecs
import cmd
+import logging
import optparse
-import readline # including readline makes cmd.Cmd.cmdloop() smarter
+try:
+ import readline # including readline makes cmd.Cmd.cmdloop() smarter
+except ImportError, e:
+ import logging
+ logging.warn('Could not import readline, bash-like line editing disabled.')
import shlex
from ..command import CommandExit, Exit, Command, Argument, StoreValue
+from ..engine import CommandMessage
from ..interaction import Request, BooleanRequest, ReloadUserInterfaceConfig
-from ..ui import UserInterface, CommandMessage
+from ..ui import UserInterface
from ..util.convert import from_string
from ..util.encoding import get_input_encoding, get_output_encoding
def __init__(self, *args, **kwargs):
super(DoCommand, self).__init__(*args, **kwargs)
self.parser = CommandLineParser(self.command, self.name_fn)
+ self.log = logging.getLogger('hooke')
def __call__(self, args):
try:
self.cmd.stdout.write(str(e).lstrip()+'\n')
self.cmd.stdout.write('Failure\n')
return
- print args
+ self.log.debug('executing %s with %s' % (self.command.name, args))
self.cmd.inqueue.put(CommandMessage(self.command, args))
while True:
msg = self.cmd.outqueue.get()
argv = shlex.split(line, comments=True, posix=True)
if len(argv) == 0:
return None, None, '' # return an empty line
- elif argv[0] == '?':
- argv[0] = 'help'
- elif argv[0] == '!':
- argv[0] = 'system'
- return argv[0], argv[1:], line
+ cmd = argv[0]
+ args = argv[1:]
+ if cmd == '?':
+ cmd = 'help'
+ elif cmd == '!':
+ cmd = 'system'
+ return cmd, args, line
def do_help(self, arg):
"""Wrap Cmd.do_help to handle our .parseline argument list.
return cmd.Cmd.do_help(self, '')
return cmd.Cmd.do_help(self, arg[0])
- def empytline(self):
+ def emptyline(self):
"""Override Cmd.emptyline to not do anything.
Repeating the last non-empty command seems unwise. Explicit
"""
pass
+
class CommandLine (UserInterface):
"""Command line interface. Simple and powerful.
"""