Move command registering to Command object
This commit is contained in:
parent
e184ace8cb
commit
536a7ef1e6
@ -117,14 +117,10 @@ class register: # noqa: N801,N806 pylint: disable=invalid-name
|
|||||||
else:
|
else:
|
||||||
assert isinstance(self._name, str), self._name
|
assert isinstance(self._name, str), self._name
|
||||||
name = 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,
|
cmd = command.Command(name=name, instance=self._instance,
|
||||||
handler=func, **self._kwargs)
|
handler=func, **self._kwargs)
|
||||||
objects.commands[name] = cmd
|
cmd.register()
|
||||||
return func
|
return func
|
||||||
|
|
||||||
|
|
||||||
|
@ -521,3 +521,12 @@ class Command:
|
|||||||
def takes_count(self):
|
def takes_count(self):
|
||||||
"""Return true iff this command can take a count argument."""
|
"""Return true iff this command can take a count argument."""
|
||||||
return any(arg.count for arg in self._qute_args)
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user