Skip to content
Browse files

Allow abbreviations to glob options

Signed-off-by: Steve Bennett <steveb@workware.net.au>
  • Loading branch information...
1 parent 7bf43eb commit aff4583eebb137bfbe740cce1f91d158344d9cb7 @msteveb committed Sep 22, 2012
Showing with 26 additions and 14 deletions.
  1. +26 −14 glob.tcl
View
40 glob.tcl
@@ -116,36 +116,48 @@ proc glob {args} {
set nocomplain 0
set base ""
- while {[llength $args] > 0} {
- switch -glob -- [set switch [lindex $args 0]] {
- -directory {
- if {[llength $args] < 2} {
- return -code error "missing argument to \"$switch\""
- }
- set base [lindex $args 1]
- set args [lrange $args 1 end]
+ set n 0
+ foreach arg $args {
+ if {[info exists param]} {
+ set $param $arg
+ unset param
+ incr n
+ continue
+ }
+ switch -glob -- $arg {
+ -d* {
+ set switch $arg
+ set param base
}
- -nocomplain {
+ -n* {
set nocomplain 1
}
- -tails {
+ -t* {
# Ignored for Tcl compatibility
}
-* {
return -code error "bad option \"$switch\": must be -directory, -nocomplain, -tails, or --"
}
- -- -
+ -- {
+ incr n
+ break
+ }
* {
break
}
}
- set args [lrange $args 1 end]
+ incr n
+ }
+ if {[info exists param]} {
+ return -code error "missing argument to \"$switch\""
}
- if {[llength $args] < 1} {
+ if {[llength $args] <= $n} {
return -code error "wrong # args: should be \"glob ?options? pattern ?pattern ...?\""
}
+ set args [lrange $args $n end]
+
set result {}
foreach pattern $args {
set pattern [string map {
@@ -163,7 +175,7 @@ proc glob {args} {
lappend result $name
}
}
- }
+ }
if {!$nocomplain && [llength $result] == 0} {
return -code error "no files matched glob patterns"

0 comments on commit aff4583

Please sign in to comment.
Something went wrong with that request. Please try again.