In my TCL script I am trying to provide input argument which will be parsed using 'cmdline' package. I have defined the following in my script:
set run_options {
{input_1.arg 8 "first input argument"}
{input_2.arg 1 "second input argument"}
{msb "choose it if input data has msb first"}
{lsb "choose it if input data has lsb first"}
}
set my_usage ": \n tclsh my_src \[options] ...\noptions are:"
if {[catch {array set params [::cmdline::getoptions argv $run_options $my_usage]} msg]} {
puts "Error while parsing user options of $msg"
exit 1
}
everything look fine except that when running my script I figured out that the 'cmdline' package defines "help" option by default, but when I run my script with "-help" option the following is the output:
Error while parsing user options of my_src :
tclsh my_src [options] ...
options are:
-input_1 value first input argument <8>
-input_2 value second input argument <1>
-msb choose it if input data has msb first
-lsb choose it if input data has lsb first
-- Forcibly stop option processing
-help Print this message
-? Print this message
so, does anyone know how to use this automatically added "help" option without giving error message?
cmdline::getoptions
doesn't differentiate between-help
and an unknown option (An unrecognized option is treated like it was-?
). If you want to have different messages for the two cases, you need to use one of the the lower level functions directly in a loop, or something like the following enhanced version ofcmdline::getoptions
:Example usage: