[Ml-yokadi] YokadiOptionParser (was Re: yokadi upstream)
Sébastien Renard
Sebastien.Renard
Jeu 20 Nov 13:17:06 CET 2008
Le jeudi 20 novembre 2008, Aurélien Gâteau a écrit :
> Here is a more complete example of what I have in mind:
>
> class MyCmd(cmd):
> def parser_foo(self):
> parser = YokadiOptionParser()
> parser.add_option(...)
> ...
> return parser
>
> def do_foo(self, line):
> parser = self.parser_foo()
> options, args = parser.parse_args(line)
> ...
>
>
> def do_help(self, arg):
> parserMethod = getattr(self, "parser_" + arg)
> if parserMethod:
> parser = parserMethod()
> parser.print_usage()
> else:
> Cmd.do_help(self, arg)
>
> You just need to add a "parser_foo" method which returns a parser and
> use this function in "do_foo".
Ok, I see. You're right, it seems to be the best solution.
[...]
> > 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.
>
> That's what I did this morning. There was no need to escape quotes in
> fact: splitting with the standard split() string method instead of
> shlex.split() does the job.
It's a good compromise.
a+
--
Sébastien
Plus d'informations sur la liste de diffusion Ml-yokadi