Changeset 1914


Ignore:
Timestamp:
Sep 23, 2010 3:22:35 AM (14 years ago)
Author:
dkearney
Message:

updating getopts to handle cases where you have extra -'d arguments after a list argument.

Example:
in your tcl file if you specify an flags like:

proc fxn {args} {

Rappture::getopts args params {

list -tests "all"
list -dirs "."

}

...

and call your function like this:

fxn -tests a b c -dirs d e

in previouse versions of getopts, $params(-tests) would have the list
a b c -dirs d e
and $params(-dirs) would have the default value "."

in the new version of getopts, $params(-tests) should have the list
a b c
and $params(-dirs) should have the list
d e

this feature is used in hubchecki::runTests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/getopts.tcl

    r1913 r1914  
    128128                    error "missing value for option $first"
    129129                }
    130                 set params($first) [lrange $args 1 end]
    131                 set args ""
     130                foreach arg [lrange $args 1 end] {
     131                    if {[string index $arg 0] == "-"} {
     132                        break
     133                    }
     134                }
     135                set idx [lsearch -exact $args $arg]
     136                if {$idx == [expr [llength $args] - 1]} {
     137                    # reached the end of the $args list
     138                    # with no other -'d arguments
     139                    set params($first) [lrange $args 1 end]
     140                    set args ""
     141                } else {
     142                    # there are further -'d arguments to process
     143                    set params($first) [lrange $args 1 [expr $idx-1]]
     144                    set args [lrange $args $idx end]
     145                }
    132146            }
    133147        }
Note: See TracChangeset for help on using the changeset viewer.