[getopt-sig] ObjectCLI
Greg Ward
gward@python.net
Tue, 19 Feb 2002 21:24:36 -0500
On 14 February 2002, Shane Hathaway said:
> ObjectCLI is a class that lets you invoke methods of a Python object
> directly from the command line. The concept is similar to Zope's
> publisher, which lets you call methods directly from the Web. Say you
> created a class like this:
Hmmm. I didn't really get this idea the first time I read your post.
I've been following the thread on this, and re-read your first post. I
think I get it now, and I'm not too keen on it. Let me explain why.
> class ServerControl:
> """A proxy server."""
>
> def start(port):
> """Starts the server on the specified port."""
>
> def stop():
> """Stops the server."""
>
>
> With two or three lines of glue, you can then invoke the methods of a
> ServerControl instance directly from the command line:
>
> python server_control.py start --port=3128
> python server_control.py stop
Initially, this looks promising/interesting. But what about programs
that don't have the "sub-command" paradigm? How do you handle the
simple
program --port=3128
case? Also, what if I want to make -p and --port synonomous? How do I
express that? How would you handle standard, simple command-line
structures like
ls -Fa /home/greg
ls -l *.py
cp -pr /tmp/foo /tmp/bar
?
> You can also get the documentation of ServerControl, primarily derived
> from the docstrings:
>
> python server_control.py --help
Interesting idea, but I worry about the overloading of docstrings.
IMHO, method/function docstrings are most useful for someone reading the
code: if I want to call function f, what arguments do I pass in, what
types must they be, what do they mean, how do they interact, what
happens to them, and what are the return values? Those are very
different goals from the user of a program who wants to know what the
"start" sub-command does.
Also, where does the help for, eg., "--port" come from? Are your method
docstrings structured so that help for individual options (method
arguments) can be pulled out?
> Major benefits:
>
> - You almost never have to look up any library documentation to write
> new command line utilities. You just write a regular Python class.
I'm skeptical of that. *You* almost never have to look up any
documentation, but you wrote it. Likewise, I hardly ever have to look
at the Optik docs. It's always obvious to the person who designed and
wrote it, and rarely to the poor schmo trying to use it.
> - The command line arguments and the implementation are less likely to
> fall out of sync.
I'm not sure what you mean by "implementation".
> - The documentation comes directly from the docstrings.
Again, I'm not convinced this is a benefit.
Finally, you have alluded to a prototype implementation of ObjectCLI --
where?
Greg
--
Greg Ward - Linux geek gward@python.net
http://starship.python.net/~gward/
Vote Cthulhu -- why settle for a lesser evil?