[Ml-yokadi] YokadiOptionParser (was Re: yokadi upstream)

Sébastien Renard Sebastien.Renard
Jeu 20 Nov 09:32:18 CET 2008


Le mercredi 19 novembre 2008, Aurélien Gâteau a écrit :
> > 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.

Yes, that's was my idea. Centralise parser definition, and, at init time, 
generate all help doctring.
I know, it is eveil to abuse of dynamic stuff...

> > 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")

It is much more clear and simple indeed. But how to extract parser for foo 
function wihtout centralise parser definition in a dict or something like 
this ?

> > Anyway, I think we will have to centralize a little bit parser
> > definitions.
>
> What would you like to centralize?

See above. How to get parser for function foo without that if parser is 
defined into function foo ?

> 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.

Argh. We need something simple. Escaping quote is not yoakdi spirit (simple 
and intuitive tool).

> 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?

We need quote for : 
- task title and definition (language quote)
- argument delimiting when they have space

Can't we forbid space on argument and so allow free language quote in string ? 
For that, we could automagically escape all quotes before parsing.

a+
-- 
Sébastien


Plus d'informations sur la liste de diffusion Ml-yokadi