[Python-Dev] Python long command line options

Heiko Wundram me+python-dev at modelnine.org
Thu May 4 21:25:49 CEST 2006


Am Donnerstag 04 Mai 2006 16:21 schrieb Fredrik Lundh:
> I'm +1 on adding --help and --version, +1 on adding -? and /? for windows
> only, -0=slightly sceptical if adding a generic long option machinery is
> worth it, and -1 on a guessing machinery.

I've updated the patch on the SourceForge tracker to reflect this criticism. 
In effect:

1) --help and --version are added unconditionally on all platforms
2) -? and /? are recognized on Windows, as are /help and /version,
   because / is just a different longopt-specifier on Windows for the
   getopt machinery in _PyOS_GetOpt
3) I removed the prefix matching
4) I removed the last reference to a string function in _PyOS_GetOpt
5) --command, which was a test-case for me, has been removed as a long-opt
   again.

The module has undergone a complete rewrite with this patch, and I've adapted 
the module header to reflect this (because there's absolutely no legacy code 
left now, which can be seen pretty clearly when you look at a diff...). The 
usage output in Modules/main.c has also been adapted, as have the test cases 
in test_cmd_line.py for usage and version, which pass cleanly for me.

The patch doesn't produce any warnings on gcc 3.4.6, and I've tested the 
Windows-specific additions to _PyOS_GetOpt by injecting MS_WINDOWS into the 
compilation on my system for Python/getopt.c, and it produces correct results 
on /?, /version, /help, and -?, but as I said before I can't tell whether 
there are bugs left which surface when it's being compiled on Windows 
directly, as I don't have a Windows system to test this patch on.

Anyway, would be glad to hear any feedback.

--- Heiko.


More information about the Python-Dev mailing list