mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 01:52:56 +01:00
Cmds: Add parsed args as attribute
The parsed args container is passed to the run() function and friends for convenient use. Sometimes, though, the base classes or umbrella commands need to make use of it, too, even more so as they may define command line arguments via add_arguments(). However, run() or _run() or whatever is never called on them, neither any other callback, so make args available to them as a member variable. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
055c008a33
commit
2ec6e72cff
1 changed files with 5 additions and 5 deletions
|
|
@ -89,9 +89,9 @@ class Cmds: # export
|
|||
self.__add_cmd_to_parser(cmd, subparsers)
|
||||
|
||||
async def __run(self, argv=None):
|
||||
args = self.__parser.parse_args(args=argv)
|
||||
set_flags(args.log_flags)
|
||||
set_level(args.log_level)
|
||||
self.args = self.__parser.parse_args(args=argv)
|
||||
set_flags(self.args.log_flags)
|
||||
set_level(self.args.log_level)
|
||||
|
||||
# This is the toplevel parser, i.e. no func member has been added to the args via
|
||||
#
|
||||
|
|
@ -101,11 +101,11 @@ class Cmds: # export
|
|||
# super().add_parser(parsers)
|
||||
# Cmd.__parser.set_defaults(func=self.run)
|
||||
#
|
||||
if not hasattr(args, 'func'):
|
||||
if not hasattr(self.args, 'func'):
|
||||
self.__parser.print_help()
|
||||
return None
|
||||
|
||||
return await args.func(args)
|
||||
return await self.args.func(self.args)
|
||||
|
||||
def __del__(self):
|
||||
if self.__own_eloop:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue