- info commands ?pattern?
MGS 2004-03-14: Don't forget that info commands will not tell you the names of all possible commands - some commands are auto-loaded using the unknown and auto_load mechanism. To get a list of all possible commands, I use something like this:
proc commands {{pattern *}} { return [lsort -unique [concat [ info commands $pattern] [ array names ::auto_index $pattern] ]] } # example set tk_commands [commands ::tk::*]Note: this will extract commands from the auto_index array which match the specified pattern and commands from all descendant namespaces (this may not be what you want or expect). See array names for more info.You could try this version instead:
proc commands {{pattern *}} { if {![string match ::* $pattern]} { regsub -- :::: [uplevel namespace current]::$pattern :: pattern } set auto [array names ::auto_index $pattern] set list [info commands $pattern] foreach c $auto { if {![string match ${pattern}::* $c]} {lappend list $c} } return [lsort -unique $list] } # example set tk_commands [commands1 ::tk::*] puts "Found \[[llength $tk_commands]\] commands:\n[join $tk_commands \n]"This version will return a list of all fully-qualified commands in the calling namespace.
In namespace with partly qualified commands edit
HaO 2013-08-06: Don't know why, but to check if a ttk widget command exists (like ttk::spinbox which was introduced later), one must use ::ttk::spinbox to get a result with 'info commands':% namespace eval gui {info command ttk::spinbox} % namespace eval gui {info command ::ttk::spinbox} ::ttk::spinbox % namespace eval gui {ttk::spinbox .s} .s