def __init__(self, name=None, commands=None, **attrs): """ Overcharge the init of the instance to add the commands coming from the file. """ super(AllGroup, self).__init__(name=name, commands=commands, **attrs) self.command_manager = CommandManager() self.dynamic_commands = [] for command in self.command_manager.build_commands(): self.add_command(cmd=command) self.dynamic_commands.append(command.name)
class CommandManagerTestCase(unittest.TestCase): def setUp(self): self.command_manager = CommandManager() self.existing_commands = ["help", "version"] def test_get_existing_command(self): command = self.command_manager.get_command("help") self.assertIsNotNone(command) def test_get_non_existing_command(self): command = self.command_manager.get_command("fudnuck") self.assertIsNone(command) def test_command_list(self): command_list = self.command_manager.get_command_list() self.assertEqual(len(command_list), len(self.existing_commands)) for i in range(0, len(self.existing_commands) - 1): self.assertIsNotNone( self.command_manager.get_command(self.existing_commands[i]))
def __init__(self): if self.instance is not None: raise Exception("This class is a singleton!") else: Bot.instance = self from src.command_manager import CommandManager self.command_manager = CommandManager(self) super().__init__()
class AllGroup(DYMMixin, HelpColorsGroup, click.Group): # pylint: disable=too-many-public-methods def __init__(self, name=None, commands=None, **attrs): """ Overcharge the init of the instance to add the commands coming from the file. """ super(AllGroup, self).__init__(name=name, commands=commands, **attrs) self.command_manager = CommandManager() self.dynamic_commands = [] for command in self.command_manager.build_commands(): self.add_command(cmd=command) self.dynamic_commands.append(command.name) def get_command(self, ctx, cmd_name): """ Overcharge the method to handle the special case of the dynamic commands.""" # The dynamic commands use a lambda as callback. This lambda should be set at the trigger time. # If we use the command stored in the self.commands of the instance, the callback will have stored # the latest lambda built. That mean all the dynamic commands will open the same url, the latest # registered. if cmd_name in self.dynamic_commands: return core.build_command( cmd_name, self.command_manager.commands[cmd_name]['url']) return super(AllGroup, self).get_command(ctx, cmd_name)
def setUp(self): self.command_manager = CommandManager() self.existing_commands = ["help", "version"]
def setUp(self): self.command_manager = CommandManager() self.help_command = HelpCommand(self.command_manager)
def deregister(name): """ Remove a command from the list of commands.""" command_manager = CommandManager() if command_manager.safe_delete(name): click.echo("Removed {} from the list of commands".format(name))
def register(name, url): """Add an url to the list of commands.""" command_manager = CommandManager() command_manager.add(name, {'url': url})