【发布时间】:2021-01-19 16:26:46
【问题描述】:
在我的 TCL 脚本中,我试图提供将使用“cmdline”包解析的输入参数。我在脚本中定义了以下内容:
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
}
一切看起来都很好,除了在运行我的脚本时我发现'cmdline'包默认定义了“帮助”选项,但是当我使用“-help”选项运行我的脚本时,输出如下:
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
那么,有谁知道如何使用这个自动添加的“帮助”选项而不给出错误消息?
【问题讨论】:
-
不要打印出错误消息中的“Error while...”部分?
-
对,就是
puts $msg -
您可能错过了我在其他情况下使用“错误”的要点。例如:如果我提供了错误的选项,那么我应该得到这个“错误”。但“帮助”不应该是一个错误。
-
cmdline::getoptions不区分-help和未知选项;他们都提出了同样的错误。 (如果您查看源代码,未知选项的处理方式与-?完全相同)
标签: tcl cmdline-args