[getopt-sig] Comparing option libraries

Russ Cox rsc@plan9.bell-labs.com
Mon, 25 Feb 2002 14:47:05 -0500


Have you significantly changed the Optik library
since this discussion started?  If I'd seen something
like http://optik.sourceforge.net/ripoff_optik.py
instead of the example at http://optik.sourceforge.net/,
I wouldn't have made such a big deal about the iterator.

What if Optik defined two subclasses, one that takes
no arguments and one that takes one argument?
And why not make type a real type instead of a string?
Further, what if the action string could be something
to eval instead of needing to be a canned action string?

Then we can remove most of the noise:

option_list = [
	Helptext("\nVerbosity options:"),
	Optflag("-v", action="verbose += 1",
		help="increase verbosity level"),
	Optarg("--verbose", var="V", type=int,
		help="verbosity level"),
	Optflag("-q", "--quiet", action="verbose = 0",
		help="run silently (verbosity=0)"),

	Helptext("\nRipping options:"),
	Optarg("-d", "--device",
		help="device file to open (default: %s on this platform)"
			% cdrom.get_default_device()),
	Optarg("-b", "--output-base", var="DIR",
		help="base output directory"),
	Optarg("-t", "--tracks", 
		help="tracks to rip (default: all) (example: 1,2-5,8)"),
	Optflag("-p", "--use-pipes", "--synchronous",
		help="use named pipes for intermediate output "
			"(uses less temporary disk space, works great "
			"if encoding is faster than ripping) [default]"),
	Optflag("-f", "--use-files", "--asynchronous", action="use_pipes = 0",
		help="use real files for intermediate output (uses more "
			"temporary disk space, but should be more reliable "
			"if ripping is faster than encoding, and will free "
			"up your CD-ROM drive sooner)"),
	Optflag("-k", "--keep-tmp",
		help="put temporary (.wav) files in output dir, and don't "
			"delete them when done with them (implies -f)"),
	Optflag("-R", "--rip-only",
		help="just do digital audio extraction -- no encoding "
			"(implies -k, -f)"),
	Optflag("-P", "--playback",
		help="play encoded audio files as encoding proceeds"),
	Optflag("-e", "--eject",
		help="eject CD when finished"),

	Helptext("\nTagging options:"),
	Optarg("-A", "--artist",
		help="use ARTIST for tagging and file naming "
			"(overrides CDDB/CDindex)"),
	Optarg("-L", "--album",
		help="use ALBUM for tagging and file naming"),
	Optarg("-D", "--disc", type=int,
		help="set disc number to DISC (for multi-disc sets)"),
	Optarg("-y", "--year",
		help="use YEAR for tagging"),
	Optarg("--offset", type=int, default=0,
		help="add OFFSET to track numbers for tagging and file naming"),
]

Finally, there should be some similar way to specify how to parse the
rest of the command line; otherwise you're encouraging people
to use options when they're not really necessary, because
they get the nice benefits of things like type checking.

Russ