def parse_line(self, line): cmd = False words = line.split() if len(words) == 0: return False cmd_name = words[0] try: args = words[1:] except: args = None cmd = find_cmd(cmd_name, self.cmd_modules) if not cmd: self.tell('No such command: %s\n' % (cmd_name, )) return False try: if args is not None: kwargs = {} normargs = [] for arg in args: if arg.startswith('--'): name, value = arg[2:].split('=') kwargs[name] = value elif arg.startswith('-'): for name in arg[1:]: kwargs[name] = True else: normargs.append(arg) return getattr(cmd, 'do_%s' % (cmd_name, ))(self, *normargs, **kwargs) except TypeError: self.tell('Too many/few arguments to given to %s\n' % (cmd_name, )) return False except: pass return False
def do_help(obj, cmd_name=None): """ usage: help [command] returns command specific help or this help message """ if cmd_name: cmd = find_cmd(cmd_name, obj.cmd_modules) try: doc = getattr(cmd, "do_%s" % (cmd_name,)).__doc__ except: doc = "No help for this command.\n" obj.tell(trim(doc)) else: obj.tell("This is stirling mud. Try `help <command name>` for help " + "on specific commands\n")
def do_help(obj, cmd_name=None): ''' usage: help [command] returns command specific help or this help message ''' if cmd_name: cmd = find_cmd(cmd_name, obj.cmd_modules) try: doc = getattr(cmd, 'do_%s' % (cmd_name, )).__doc__ except: doc = 'No help for this command.\n' obj.tell(trim(doc)) else: obj.tell('This is stirling mud. Try `help <command name>` for help ' + 'on specific commands\n')