Use objects in cmd_dict
This commit is contained in:
parent
1d88bb7c9c
commit
7c9b6bdbde
@ -16,7 +16,7 @@ class CommandParser(QObject):
|
|||||||
parts = text.strip().split()
|
parts = text.strip().split()
|
||||||
cmd = parts[0]
|
cmd = parts[0]
|
||||||
args = parts[1:]
|
args = parts[1:]
|
||||||
obj = cmd_dict[cmd]()
|
obj = cmd_dict[cmd]
|
||||||
try:
|
try:
|
||||||
obj.check(args)
|
obj.check(args)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
@ -32,7 +32,7 @@ class Command(QObject):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def bind(cls):
|
def bind(cls):
|
||||||
if cls.name:
|
if cls.name:
|
||||||
cmd_dict[cls.name] = cls
|
cmd_dict[cls.name] = cls()
|
||||||
|
|
||||||
def check(self, *args):
|
def check(self, *args):
|
||||||
if ((isinstance(self.nargs, int) and len(args) != self.nargs) or
|
if ((isinstance(self.nargs, int) and len(args) != self.nargs) or
|
||||||
|
Loading…
Reference in New Issue
Block a user