[getopt-sig] The bake-off
holger@trillke.net
holger@trillke.net
Thu, 30 May 2002 16:21:53 +0200
[Moore, Paul Thu, May 30, 2002 at 02:39:29PM +0100]
> From: holger@trillke.net [mailto:holger@trillke.net]
> > thanks! I understand the criticism. Bear in mind though that
> > i was *not* suggesting an alternative to Optik.
>
> That wasn't clear to me at the time... Sorry.
probably my fault also.
> > the idea was to make it *even cheaper* to write cmdline-tools
> > with a rich interface. The basic idea is to construct a
> > 'namespace'-mapping between the shell-cmdline and a python
> > function (or class). I suggested to use Optik as the backend
> > for this. I was (and probably still am <wink>) willing to
> > implement this but it is difficult if there is no feedback :-)
>
> It sounds like you're essentially talking about an "application framework"
> for simple command-line type scripts. If so, then my feeling is that it's a
> nice idea, and probably something I'd play with occasionally. I don't know
> if it would get much use in practice, though - it generally isn't too hard
> to use something like getopt/Optik "by hand".
true enough :-)
btw, Zope and other web-frameworks map an URL to a method in python as
well<wink>. I think that providing glue code in the standard lib
that maps the command line to a python function would considerably
lower the barrier to
a) make up a nice-for-the-user-and-programmer cmdline-tool.
b) offer your tool to others (which usually means it will be
improved etc.pp.)
> I'm not too bothered by the introspection aspect - Greg's concern that it's
> excessively "clever" isn't a problem to me if it's behind the scenes.
it's mostly straight forward. there is only one real problem...
e.g. take this mapping [*]:
def function(
mode=('-m','%s','text'), # output mode can be 'html' or 'text'
*files # list of input files to process
)
it's not difficult to introspect the default values (the argspec)
of the parameters. But it is somewhat tricky
to get the line documentation (#...) after each attribute.
Note, that is easy enough to call 'inspect.getsource(xyz)' to
get the information, BUT the problem is:
intospection generally does not work for objects living in
the __main__ module :-(
There are known workarounds but they are not pretty.
> If you implement this, I promise I'll download it and try it out :-)
i will someday :-) In the meantime i have done a reimplementation
of the rlcompleter (command line completer) which works pretty nice
plus some other stuff...
cheers,
holger
[*] the more i think about it: Maybe it would be more practical
and natural to map the cmdline to a class ...