[getopt-sig] More about commands on the command line

Matthias Urlichs smurf@noris.de
Fri, 8 Mar 2002 14:06:05 +0100


Hi,

A.T. Hofkamp:
> Ok, on to my answer on the challenging question of Matthias:
> 
Thank you. ;-)

> It makes options and (command) more equal citizens.

Ok, that's a valid point, though you also have to consider arguments
(either to the options, or to the program).

I wonder if, with all the generality, people who try to use the package
would wonder "how the heck do I do the _common_case_". Packages like
Optick handle the common case well (and reasonably seamlessly) and force
people to go through some number of hoops for the special stuff, which is
something i consider a Good Thing.

> * With the equal status of commands and options, I can have optional dashes,
>   like in 'tar xzf myfile.tgz'. Not pretty and not recommanded, but it fits in
>   my solution without major head aches.

Note that this is also a "magic" command, i.e. it rips itself apart just
like you "-spam" example.

> * With my generic solution, the only difference that remains between options
>   and commands is the magic involved in decoding stuff like '-spam'.

(but only if it's the first argument) and might be better handled by
the sufficiently simple

	if not sys.argv[1].startswith('-'):
		sys.argv[1] = '-' + sys.argv[1]

(NOTE: This test doesn't handle corner cases like 'no arguments' or
       'empty argument'.)

>   this strange. Why is there no such magic with commands ?

Because people are lazy, and typing "-s -p -a -m" is three times as much
work as typing "-spam". Note that the "magic" depends on neither s,p, nor a
taking an argument.

Besides, traditionally Unix doesn't _have_ commands. It has differrent
tools. I consider "rpm -q" a totally different tool from "rpm -U", which
should have different access privileges and whatnot. Thus, what RPM 4 does
internally is Not A Surprise:

$ strace -e execve /bin/rpm -q foo
execve("/bin/rpm", ["/bin/rpm", "-q", "foo"], [/* 55 vars */]) = 0
execve("/usr/lib/rpm/rpmq", ["/usr/lib/rpm/rpmq", "-q", "--", "foo"], [/* 55 vars */]) = 0 
package foo is not installed
$

They should have done that right in the first place.

> That may or may not be bad, depending on the aim of the option processing that
> we envision for Python.
> 
Your code certainly helps with (eventually ;-) arriving at some sort of
consensus as to what we want to accomplish.

-- 
Matthias Urlichs     |     noris network AG     |     http://smurf.noris.de/