[Ml-yokadi] YokadiOptionParser (was Re: yokadi upstream)
Aurélien Gâteau
aurelien.gateau
Mer 19 Nov 22:43:34 CET 2008
Sébastien Renard wrote:
> Le mercredi 19 novembre 2008, Aurélien Gâteau a écrit :
>> Sébastien Renard wrote:
>>> Le mardi 18 novembre 2008, Aurélien Gâteau a écrit :
>>>>> Good. Did you implement it in common class in order to make it «
>>>>> transparent » for all commands ?
>>>> Hum... no, there is no common class anymore :/.
>>> I see ;-)
>>>
>>>> The parser needs to be
>>>> explicitly instantiated because you need to add your command options to
>>>> it.
>>> Ok. It would be cool to generate command help directly from parser
>>> definition to avoid repeating ourselves.
>> Would be nice, but I am not sure how to get the docstring to execute
>> some code :/
>
> docstring can be get or set via the __doc__ attribute of each function.
Yes, I know that. In fact YokadiOptionParser accept the function
docstring as a parameter so that "foo --help" prints the same as "help
foo". But it is not optimal, I would prefer the docstring to be the
parser help output.
> Another way of generating command help is to define help_foo function for the
> do_foo function. This mechanism is done by the Cmd class.
We could add a parser_foo() function which would return a parser for the
foo command. This way do_foo() can use it, and we can override do_help()
to do something like this:
if function parser_foo exist:
parser = self.parser_foo()
parser.print_usage()
else:
cmd.do_help(self, "foo")
> Anyway, I think we will have to centralize a little bit parser definitions.
What would you like to centralize?
I just stumbled on a problem with the parser though: it split the line
in a string list using shlex.split(), which causes single and double
quotes to be interpreted. As a result, calling this:
t_add prj can't read .bar files
Will raise a ValueError("No closing quotation") exception. You now need
to escape the quote.
I don't like this, but on the other hand having a real parser make it
possible to implement much more powerful commands. Any idea on this?
Aurélien
Plus d'informations sur la liste de diffusion Ml-yokadi