ArgParseInated object¶
-
class
ArgParseInated
(parseinator, **new_attributes)¶
This class is meant to create sub classes that automatically expose the
write()
, writeln()
methods, the args
and cfg
attributes of the ArgParseInator
.
Plus expose all passed new_attributes which will passed by the
ArgParseInator.check_command()
.
It has also the __preinator__ method which is called just at the
__init__()
end.
So we can use it to do some extra action before the command is execute.
class Greetings(ArgParseInated):
"""
Greet somebody.
"""
@arg()
def ciao(self):
"""
say ciao.
"""
self.writeln(self.prefix, "ciao to", self.name)
ArgParseInator().check_command(prefix="We say", name="Luca")
Note
We can specify __cmd_name__, __arguments__, __shared_arguments__ to do some more trick, see Within classes .
__preinator__¶
The original name was __prepare__ but I’ve changed it to avoid problems.
It’s just called at the end of the __init__()
method and is intended to
do some action before ArgParseInator
executes the command.
class Greetings(ArgParseInated):
"""
Greet somebody.
"""
@arg("name", help="The name")
def ciao(self, name):
"""
say ciao.
"""
self.writeln("We say ciao to", name)
def __preinator__(self):
if self.args.name.lower() == 'luca':
self.args.name = "who? Nobody?"
ArgParseInator().check_command()