Skip to content

Commit

Permalink
update some weird exception message
Browse files Browse the repository at this point in the history
  • Loading branch information
HugeBrain16 committed Aug 27, 2021
1 parent 7972ab0 commit f253748
Showing 1 changed file with 8 additions and 28 deletions.
36 changes: 8 additions & 28 deletions cmdtools/ext/command.py
Expand Up @@ -142,7 +142,7 @@ async def run(self, cmd, attrs: dict = None):
attrs = {}

if not isinstance(cmd, cmdtools.Cmd):
raise TypeError("cmd is not a cmdtools Cmd class")
raise TypeError(f"object {type(cmd)} is not a Cmd instance")

for command in self.commands:
if command.name == cmd.name or cmd.name in command.aliases:
Expand Down Expand Up @@ -235,7 +235,7 @@ async def run(self, cmd: cmdtools.Cmd, attrs: dict = None):
"""run command from parsed command object"""

if not isinstance(cmd, cmdtools.Cmd):
raise TypeError("cmd is not a cmdtools Cmd class")
raise TypeError(f"object {type(cmd)} is not a Cmd instance")

if attrs is None:
attrs = {}
Expand Down Expand Up @@ -269,7 +269,7 @@ async def run(self, cmd: cmdtools.Cmd, attrs: dict = None):
"""run command from parsed command object"""

if not isinstance(cmd, cmdtools.Cmd):
raise TypeError("cmd is not a cmdtools Cmd class")
raise TypeError(f"object {type(cmd)} is not a Cmd instance")

if attrs is None:
attrs = {}
Expand Down Expand Up @@ -320,14 +320,7 @@ def load_module(self, load_classes):

if inspect.isclass(obj_) and obj_.__module__ == module.__name__:
if isinstance(obj_(), CommandObject):
cobj = obj_()

if cobj.name not in get_command_names(self.commands):
self.commands.append(cobj)
else:
raise DuplicateCommandNameError(
f"Command with name '{cobj.name}' is already exist in command container"
)
self.commands.append(obj_())
else:
self.commands.append(CommandObject(module))

Expand Down Expand Up @@ -363,29 +356,16 @@ def load_commands(self, search_tree, load_classes):
+ file.rsplit(".py", 1)[0]
)
if self.load_classes is False:
cobj = CommandObject(module, file.rsplit(".py", 1)[0])
if cobj.name not in get_command_names(self.commands):
self.commands.append(cobj)
else:
raise DuplicateCommandNameError(
f"Command with name '{cobj.name}' is already exist in command container"
)
self.commands.append(
CommandObject(module, file.rsplit(".py", 1)[0])
)
else:
for obj in dir(module):
obj_ = getattr(module, obj, None)

if inspect.isclass(obj_) and obj_.__module__ == module.__name__:
if isinstance(obj_(), CommandObject):
cobj = obj_()

if cobj.name not in get_command_names(
self.commands
):
self.commands.append(cobj)
else:
raise DuplicateCommandNameError(
f"Command with name '{cobj.name}' is already exist in command container"
)
self.commands.append(obj_())


def get_command_names(commands: list, get_aliases=False):
Expand Down

0 comments on commit f253748

Please sign in to comment.