[英]Tcl - How to get the list of all possible sub-commands/switches for a given tcl command (including user defined commands)
For a given tcl user-defined command (for instance, "user_command -switch_A -switch_B") I would like to get all the possible sub-commands/switches to be used with that command as a list.对于给定的 tcl 用户定义命令(例如,“user_command -switch_A -switch_B”),我想获取所有可能的子命令/开关以作为列表与该命令一起使用。 Below is an example of the tcl regexp switches available: Regexp valid switches
以下是可用的 tcl regexp 开关的示例: Regexp valid switches
I would like to use it to compare "implemented and public sub-commands/switches VS documented and public sub-commands/switches" for a given program.我想用它来比较给定程序的“已实现和公共子命令/开关 VS 已记录和公共子命令/开关”。
I can get the available commands from "info commands" command, but I'm struggling to get possible valid sub-commands/switches for a given command.我可以从“信息命令”命令中获取可用命令,但我正在努力为给定命令获取可能的有效子命令/开关。
The normal way is to use a deliberately wrong option name (such as -!
) and to catch and parse the result.正常的方法是使用故意错误的选项名称(例如
-!
)并捕获和解析结果。
proc listOptions args {
try {
{*}$args -!
} on error msg {
if {[regexp {should be one of (.*)} $msg -> items]} {
return [string map {{, or } { } , {}} $items]
}
}
error "no option list from $args"
}
puts [listOptions chan configure stdout]
To find subcommands for commands that are implemented as namespace ensemble
s, you can do:要查找作为
namespace ensemble
实现的命令的子命令,您可以执行以下操作:
set cmd "string"
set map [namespace ensemble configure $cmd -map]
dict keys $map
# => bytelength cat compare equal first index is last length map match range repeat replace reverse tolower toupper totitle trim trimleft trimright wordend wordstart
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.