def complete_unsetg(self, text, *args, **kwargs): if text: return [ ' '.join((attr, "")) for attr in GLOBAL_OPTS.keys() if attr.startswith(text) ] else: return GLOBAL_OPTS.keys()
def command_unsetg(self, *args, **kwargs): key, _, value = args[0].partition(' ') try: del GLOBAL_OPTS[key] except KeyError: utils.print_error("You can't unset global option '{}'.\n" "Available global options: {}".format(key, GLOBAL_OPTS.keys())) else: utils.print_success({key: value})
def suggested_commands(self): # TODO: sorted list, factor out generic commands """ Entry point for intelligent tab completion. Based on state of interpreter this method will return intelligent suggestions. :return: list of most accurate command suggestions """ if self.current_module: module_commands = ['run', 'back', 'set ', 'setg ', 'show ', 'check', 'exec ', 'help', 'exit'] if GLOBAL_OPTS.keys(): return itertools.chain(module_commands, ('unsetg ',)) return module_commands else: return ['use ', 'exec', 'help', 'exit', 'show ']
def complete_unsetg(self, text, *args, **kwargs): if text: return [' '.join((attr, "")) for attr in GLOBAL_OPTS.keys() if attr.startswith(text)] else: return GLOBAL_OPTS.keys()
def test_command_unsetg(self, mock_print_success): GLOBAL_OPTS['foo'] = 'bar' self.interpreter.command_unsetg('foo') self.assertNotIn('foo', GLOBAL_OPTS.keys()) mock_print_success.assert_called_once_with({'foo': ''})