def test_double_overlapping_completion(self): """Command must complete with two overlapping options.""" cmd1 = Command('configure') cmd2 = Command('terminal') cmd2.run = lambda l: "terminal output" cmd3 = Command('terminal_1') cmd3.run = lambda l: "terminal_1 output" cmd1.addChild(cmd2) cmd1.addChild(cmd3) # State 0 must print all commands followed by help message # and return None as candidates candidates = cmd1.complete('', '', 0, run=False, full_line='configure ') assert None == candidates candidates = cmd1.complete('', 't', 0, run=False, full_line='configure t') assert 'terminal ' == candidates candidates = cmd1.complete('', 't', 1, run=False, full_line='configure t') assert 'terminal_1 ' == candidates # user pressing tab on ambiguous command candidates = cmd1.complete(["terminal"], 'terminal', 0, run=False, full_line=None) assert "terminal " == candidates candidates = cmd1.complete(["terminal"], 'terminal', 1, run=False, full_line=None) assert "terminal_1 " == candidates output = cmd1.complete(["terminal"], 'configure terminal', 0, run=True, full_line='configure terminal') assert 'terminal output' == output output = cmd1.complete(["terminal_1"], 'configure terminal_1', 0, run=True, full_line='configure terminal_1') assert 'terminal_1 output' == output
def run(self, line): interface = line.split()[-1] self.interface = interface self.prompt = "RouterA(config-if-%s)" % self.interface self.prompt_delim = "#" ip = Command("ip", help="Configure ip parameters: address") address = Command("address") address.run = self.set_address self.addChild(ip).addChild(address) self.loop()