skele-cli
skele-cli copied to clipboard
Execution of Wrong "class".run() when importing Class that is lexicographicaly "lower"
So when I have the command zebra
and in class Zebra(Base)
I import class Alpaca from a different source, the main() function of the cli tries to execute run() on Alpaca. This is due to the fact that the main() method of the cli gets the commands with :
if hasattr(name.commands, k) and v: module = getattr(name.commands, k)
and then accesses name.commands[0] if name.commands[0] != "Base".
But because in name.commands[0] is Alpaca because it is beeing imported by Zebra.
There is an easy fix for that:
for (k, v) in options.items(): if hasattr(name.commands, k) and v: module = getattr(unchained.commands, k) name.commands = getmembers(module, isclass) command = [c for c in name.commands if c[0].lower() == k.lower()][0][1] command = command(options) command.run()
Here the program checks weather c[0].lower() == k.lower() (with c we iterate over name.commands and in k is the command) this way command.run() gets the right Class.
fixed in fork SchulerSimon/skele-cli