High Maintenance:
Use a "-X" convention to set state variables within the code.
Example: Code to parse this command line:
for {set i 0} {$i < [llength $argv]} {incr i} {
switch -- [llindex $argv $i] {
-d { set debug 1 }
-l { incr i; set logfile [lindex $argv $i] }
-o { set optimize 1; }
default { puts "Unrecognized argument: [lindex $argv $i]" }
}
}
$> example.tcl -d -l /tmp/logging -o
Advantage:
Disadvantage:
Use a "-varName Value" convention to set variables within the code.
Example: Code to parse this command line:
for {set i 0} {$i < [llength $argv]} {incr i} {
set arg [lindex $argv $i]
if {[string first "-" $arg] == 0} {
incr i;
eval [list set [string range $arg 1 end] [lindex $argv $i]]
} else {
puts "Bad argument: $arg"
}
}
example.tcl -debug 1 -logfile /tmp/logging -optimize 1
Advantage:
Disadvantage: