mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 09:53:32 +01:00
jwutils.Cmds: Fix empty to cmds member variable
Cmds.cmds was sometimes empty, so fix that and make sure it points to the Cmds instance it was crated by. Actually the name of the Cmds class is a bad pick, should have been App or something, so to add .app, too, as a path for future compatibility. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
c5b964a5bb
commit
edf861c985
1 changed files with 8 additions and 3 deletions
|
|
@ -12,12 +12,18 @@ from jwutils import log
|
||||||
|
|
||||||
class Cmds: # export
|
class Cmds: # export
|
||||||
|
|
||||||
|
def __instantiate(self, cls):
|
||||||
|
r = cls()
|
||||||
|
r.cmds = self # Rename Cmds class to App, "Cmds" isn't very self-explanatory
|
||||||
|
r.app = self
|
||||||
|
return r
|
||||||
|
|
||||||
def __add_cmd_to_parser(self, cmd, parsers):
|
def __add_cmd_to_parser(self, cmd, parsers):
|
||||||
parser = cmd.add_parser(parsers)
|
parser = cmd.add_parser(parsers)
|
||||||
cmd.add_arguments(parser)
|
cmd.add_arguments(parser)
|
||||||
if len(cmd.child_classes) > len(cmd.children):
|
if len(cmd.child_classes) > len(cmd.children):
|
||||||
for c in cmd.child_classes:
|
for c in cmd.child_classes:
|
||||||
cmd.children.append(c())
|
cmd.children.append(self.__instantiate(c))
|
||||||
for sub_cmd in cmd.children:
|
for sub_cmd in cmd.children:
|
||||||
subparsers = parser.add_subparsers(title='Available commands of ' + cmd.name, metavar='')
|
subparsers = parser.add_subparsers(title='Available commands of ' + cmd.name, metavar='')
|
||||||
self.__add_cmd_to_parser(sub_cmd, subparsers)
|
self.__add_cmd_to_parser(sub_cmd, subparsers)
|
||||||
|
|
@ -64,8 +70,7 @@ class Cmds: # export
|
||||||
if inspect.isabstract(c):
|
if inspect.isabstract(c):
|
||||||
continue
|
continue
|
||||||
log.slog(log.DEBUG, 'instantiating command "{}"'.format(c))
|
log.slog(log.DEBUG, 'instantiating command "{}"'.format(c))
|
||||||
cmd = c()
|
cmd = self.__instantiate(c)
|
||||||
cmd.cmds = self
|
|
||||||
#cmd.add_parser(subparsers)
|
#cmd.add_parser(subparsers)
|
||||||
self.__cmds.append(cmd)
|
self.__cmds.append(cmd)
|
||||||
for child in cmd.child_classes:
|
for child in cmd.child_classes:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue