diff --git a/qutebrowser/api/cmdutils.py b/qutebrowser/api/cmdutils.py index a90471a35..f95e984ca 100644 --- a/qutebrowser/api/cmdutils.py +++ b/qutebrowser/api/cmdutils.py @@ -117,14 +117,10 @@ class register: # noqa: N801,N806 pylint: disable=invalid-name else: assert isinstance(self._name, str), self._name name = self._name - log.commands.vdebug( # type: ignore - "Registering command {} (from {}:{})" - .format(name, func.__module__, func.__qualname__)) - if name in objects.commands: - raise ValueError("{} is already registered!".format(name)) + cmd = command.Command(name=name, instance=self._instance, handler=func, **self._kwargs) - objects.commands[name] = cmd + cmd.register() return func diff --git a/qutebrowser/commands/command.py b/qutebrowser/commands/command.py index 5c5ab1311..5422a9984 100644 --- a/qutebrowser/commands/command.py +++ b/qutebrowser/commands/command.py @@ -521,3 +521,12 @@ class Command: def takes_count(self): """Return true iff this command can take a count argument.""" return any(arg.count for arg in self._qute_args) + + def register(self): + """Register this command in objects.commands.""" + log.commands.vdebug( # type: ignore + "Registering command {} (from {}:{})".format( + self.name, self.handler.__module__, self.handler.__qualname__)) + if self.name in objects.commands: + raise ValueError("{} is already registered!".format(self.name)) + objects.commands[self.name] = self