[socal-piggies] Command-line processing in Python

John Mark Schofield root at sudosu.net
Tue Jun 9 23:10:40 PDT 2009


In the past, I've done some fairly complex handling of command-line
arguments with optparse. And when you've got a complex set of
command-line options (some of which conflict) that can become a pain
in the but.

This was a script that configured wired and wireless network setups,
based on the command-line options sent to the script. For instance, if
you specified --wifi, you'd need to specify SSID, and you'd optionally
get to enter a password (if the network was WEP, for instance). You
could not specify --wifi and --wired at the same time, or --DHCP and
--static at the same time. And if you specified --static, you'd need
to include an --ipaddress, --netmask, and --gateway.

All of this to point out that the requirements were fairly complex, as
far as command-line options go.

And when all was said and done, the code to set up optparse, check for
conflicting/erronious command-line options, and do the rest of the
processing was by far the single biggest part of the script --
dwarfing the other sections.

Yet getopt

-- 
---------------------------------------------------
John Mark Schofield
root at sudosu.net
http://www.sudosu.net
http://blog.sudosu.net
(310) 751-0022




More information about the socal-piggies mailing list