Re: Docs: The example for
- Posted by jaygade Sep 02, 2009
- 1203 views
The example for cmd_parse has a few errors in it too:
The procedure opt_extras refers to option_definition as option_definitions (the extra 's' causing an error)
The example uses the short option 'h' for 'hash'. cmd_parse complains that you cannot reuse a short definition (I believe standardize_opts uses 'h' for 'help'). I changed it to 'z'.
This was the second bug, and it confused me because it reported line 33 as causing the error (which assigned a value to option_definition) instead of line 41 (the actual call to cmd_parse). I was confused by this, although hindsight shows me that 33 was where the error was located. I don't know if this was coincidence or intended behavior (any sufficiently advanced bug is indistinguishable from a feature).
Another bug causing the example to crash:
opt_verbose should be declared as a function and return a value (1 in this case, I think??)
As output I get:
test-cmd_parse.ex options: [-v], [--verbose] Verbose output [-z], [--hash] Calculate hash values -o x, --output=x Output filename [-i x], [--import=x] An import path [-h], [--help] Display the command options [-?] Display the command options One or more additional arguments can be supplied.
Editing this: once I created the "output.txt" file, now I get another error. Seems "opt_output" should be a function too.