示例#1
0
    def parse_input(self, user_input):
        """
        Checks if a command is valid - if not, prints an error. Else, pop all
        other arguments to a list and then call the command with the given args
        """
        for arg in user_input.split():
            self.stack.push(arg)

        command = self.stack.pop()
        arguments = []
        if not command in commands_list.keys():
            #don't crash if the user accidentally presses enter
            if command==None:
                self.error("please write a command.")
            else:
                self.error("command '%s' not found." % command)
            self.writeln("Enter 'help' or '?' to get a list of commands")
            while not self.stack.is_empty():
                self.stack.pop()
            return

        while not self.stack.is_empty():
            arguments.append(self.stack.pop())
        
        self.call(command, arguments)
示例#2
0
 def callback(self, *args):
     for command in commands_list.keys():
         self.console.writeln("|-- %s%s" % (command.ljust(8), commands_list[command].help()))