[英]Tcl - How to get the list of all possible sub-commands/switches for a given tcl command (including user defined commands)
對於給定的 tcl 用戶定義命令(例如,“user_command -switch_A -switch_B”),我想獲取所有可能的子命令/開關以作為列表與該命令一起使用。 以下是可用的 tcl regexp 開關的示例: Regexp valid switches
我想用它來比較給定程序的“已實現和公共子命令/開關 VS 已記錄和公共子命令/開關”。
我可以從“信息命令”命令中獲取可用命令,但我正在努力為給定命令獲取可能的有效子命令/開關。
正常的方法是使用故意錯誤的選項名稱(例如-!
)並捕獲和解析結果。
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]
要查找作為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.