Skip to content
This repository has been archived by the owner on Oct 11, 2021. It is now read-only.

Execution of Wrong "class".run() when importing Class that is lexicographicaly "lower" #17

Open
SchulerSimon opened this issue Oct 18, 2018 · 1 comment

Comments

@SchulerSimon
Copy link

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.

@SchulerSimon
Copy link
Author

fixed in fork SchulerSimon/skele-cli

SchulerSimon pushed a commit to SchulerSimon/skele-cli that referenced this issue Nov 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant