12 Jun 2003: Here is an example of its use (http://groups.google.com/groups?th=89144039acd5554b):
package require cmdline
proc test {args} {
set options {
{first.arg 1 "1st arg"}
{second.arg 2 "2nd arg"}
{third.arg 3 "3rd arg"}
{fourth.arg 4 "4th arg"}
}
# cmdline::getoptions will throw an error for unknown option
array set params [::cmdline::getoptions args $options]
# do other stuff...
parray params
}
test -fourth last -first oneHere's a portion of another example, this one by [Eric Varsanyi]:
proc sc_dump {args} {
set ::argv0 "sc_dump"
array set arg [::cmdline::getoptions args {
{v "Verbose"}
{t "Only dump top 10 LRU"}
{hit "Sort by hit count"}
{top.arg end "Dump top N LRU"}
{main "Dump main cache"}
{unrunnable "Dump unrunnable cache"}
{i "Case insensitive expression match"}
{all "Search entire entry (otherwise SQL only)"}
}]
if {$arg(t)} {
set arg(top) 10
}
# Pick cache groups to dump
set clist {}
if {$arg(main)} {
lappend clist main
}
if {$arg(unrunnable)} {
lappend clist unrunnable
}
if {[llength $clist] == 0} {
set clist {main unrunnable}
}
...cmdline::getoptions args $optlist has a nasty side effect: it removes all of the elements from args.So, if you want to do anything with the original args after calling getoptions, save args or do it before calling getoptions.
| Category Argument Processing | Category Package, a subset of Tcllib |
|---|