dsc | 126 ++++++++++++++++++++++++++++------------------------- diff --git a/dsc b/dsc index da6b9d0e9ca189c1190ef6538f1353248bdfef2b9cf7cd56a0eabde4268fe77d..6372bb17059634a0eaa0e63680f5d5257bbc35d5a44eea23d1eca8480866408f 100755 --- a/dsc +++ b/dsc @@ -203,20 +203,28 @@ } } } -set opt [lindex $argv 1] -switch [lindex $argv 0] { +set cmd [lindex $argv 0] +set argv [lrange $argv 1 end] +set opts [list] +foreach arg $argv { + if {[string index $arg 0] != "-"} { + break + } + lappend opts $arg + set argv [lrange $argv 1 end] +} +set arg [lindex $argv 0] +switch $cmd { list { set verbose no - set prefix [lindex $argv 1] - if {$argc > 1 && [lindex $argv 1] == "-v"} { + if {[lsearch $opts -v] != -1} { set verbose yes - set prefix [lindex $argv 2] } foreach opt [walk $Schema directory] { if {![file exists $opt/title]} {continue} set name [string range $opt $([string length $Schema] + 1) end] - if {$prefix != ""} { - if {[string range $name 0 [string length $prefix]-1] != $prefix} { + if {$arg != ""} { + if {[string range $name 0 [string length $arg]-1] != $arg} { continue } } @@ -234,9 +242,9 @@ } } } add { - assure-all-list-params-exist $opt 1 - set dir [file dirname $opt] - set tail [run-checker $opt [file tail $opt]] + assure-all-list-params-exist $arg 1 + set dir [file dirname $arg] + set tail [run-checker $arg [file tail $arg]] set tail [string trimright $tail "\n"] set l [list-opt-ordered $dir] file mkdir $Stash/$dir/$tail @@ -246,91 +254,91 @@ puts $dir/$tail } reorder { set p 0 - if {[llength $argv] > 2} { - set p $(+[lindex $argv 2]) + if {[llength $argv] > 1} { + set p $(+[lindex $argv 1]) } - set dir [file dirname $opt] + set dir [file dirname $arg] set l [list-opt-ordered $dir] - set opt [file tail $opt] - set i [lsearch $l $opt] + set arg [file tail $arg] + set i [lsearch $l $arg] set l [lreplace $l $i $i] - set l [linsert $l $p $opt] + set l [linsert $l $p $arg] list-opt-reorder $dir $l } del { - if {$opt != ""} { - assure-exists $opt + if {$arg != ""} { + assure-exists $arg } - file delete -force $Stash/$opt + file delete -force $Stash/$arg } set { - assure-all-list-params-exist $opt - if {[llength $argv] > 2} { - set v [lindex $argv 2] + assure-all-list-params-exist $arg + if {[llength $argv] > 1} { + set v [lindex $argv 1] if {$v == ""} { - file delete $Stash/$opt + file delete $Stash/$arg exit } } - file mkdir "$Stash/[file dirname $opt]" - if {[is-bin $opt]} { + file mkdir "$Stash/[file dirname $arg]" + if {[is-bin $arg]} { fconfigure stdin -translation binary - exec base64 >$Stash/$opt <@stdin + exec base64 >$Stash/$arg <@stdin } else { - set v [run-checker $opt $v] - set fh [open $Stash/$opt w] + set v [run-checker $arg $v] + set fh [open $Stash/$arg w] puts -nonewline $fh $v close $fh } } has { - assure-exists $opt + assure-exists $arg } find-opt-schema { - puts [find-opt-schema $opt] + puts [find-opt-schema $arg] } get { - if {[file tail $opt] == "*"} { - set opt [file dirname $opt] - if {![file exists $Stash/$opt]} { + if {[file tail $arg] == "*"} { + set arg [file dirname $arg] + if {![file exists $Stash/$arg]} { exit } - foreach dir [list-opt-ordered $opt] { + foreach dir [list-opt-ordered $arg] { puts $dir } exit } - if {[file exists $Stash/$opt]} { - if {[is-bin $opt]} { + if {[file exists $Stash/$arg]} { + if {[is-bin $arg]} { fconfigure stdout -translation binary - exec base64 -d <$Stash/$opt >@stdout + exec base64 -d <$Stash/$arg >@stdout } else { - puts -nonewline [fileread $Stash/$opt] + puts -nonewline [fileread $Stash/$arg] } exit } - puts -nonewline [run-checker $opt ""] + puts -nonewline [run-checker $arg ""] } apply { - set pth [find-opt-schema $opt] + set pth [find-opt-schema $arg] if {[file exists $Schema/$pth/apply]} { - puts stderr "applying $opt..." - if {[catch {exec {*}[list "$Schema/$pth/apply" $opt] >@stdout 2>@stderr}]} { + puts stderr "applying $arg..." + if {[catch {exec {*}[list "$Schema/$pth/apply" $arg] >@stdout 2>@stderr}]} { exit 1 } exit } if {[file exists $Schema/$pth/*]} { set rc 0 - foreach dir [readents $Stash/$opt directory] { - if {[catch {exec {*}[list dsc apply $opt/$dir] >@stdout 2>@stderr}]} { + foreach dir [readents $Stash/$arg directory] { + if {[catch {exec {*}[list dsc apply $arg/$dir] >@stdout 2>@stderr}]} { set rc 1 } } exit $rc } - foreach ent [readents $Schema/$opt directory] { - if {[catch {exec {*}[list dsc apply $opt/$ent] >@stdout 2>@stderr}]} { + foreach ent [readents $Schema/$arg directory] { + if {[catch {exec {*}[list dsc apply $arg/$ent] >@stdout 2>@stderr}]} { set rc 1 } } @@ -338,13 +346,13 @@ } diff { set dirsSaved [file tempfile $TMPDIR/dsc.dirsSaved.XXXXXX] set fh [open $dirsSaved w] - foreach fn [walk $Saved/$opt directory] { + foreach fn [walk $Saved/$arg directory] { puts $fh [string range $fn [string length $Saved]+1 end] } close $fh set dirsStash [file tempfile $TMPDIR/dsc.dirsStash.XXXXXX] set fh [open $dirsStash w] - foreach fn [walk $Stash/$opt directory] { + foreach fn [walk $Stash/$arg directory] { puts $fh [string range $fn [string length $Stash]+1 end] } close $fh @@ -353,7 +361,7 @@ puts -nonewline [read $fh] catch {close $fh} file delete $dirsSaved file delete $dirsStash - set fh [open [list |diff -urN $Saved/$opt $Stash/$opt]] + set fh [open [list |diff -urN $Saved/$arg $Stash/$arg]] set prefixSaved "--- $Saved/" set prefixSavedLen [string length $prefixSaved] set prefixStash "+++ $Stash/" @@ -375,8 +383,8 @@ } catch {close $fh} } revert { - catch {file delete -force $Stash/$opt} - catch {exec {*}[list cp -a $Saved/$opt $Stash/$opt]} + catch {file delete -force $Stash/$arg} + catch {exec {*}[list cp -a $Saved/$arg $Stash/$arg]} } commit { file delete -force $Saved.bak @@ -419,9 +427,9 @@ puts "$name [lindex $v 0]" } } export-raw { - set dirs [walk $Saved/$opt directory] - if {$opt != ""} { - set dirs [list $Saved/$opt {*}$dirs] + set dirs [walk $Saved/$arg directory] + if {$arg != ""} { + set dirs [list $Saved/$arg {*}$dirs] } puts "-- .dirs --" foreach fn $dirs { @@ -457,7 +465,7 @@ } } } export { - set exporter [open [list |$argv0 export-raw $opt]] + set exporter [open [list |$argv0 export-raw $arg]] fconfigure $exporter -translation binary lassign [pipe] r w set hasher [open [list |$argv0 csum >@$w] w] @@ -546,12 +554,12 @@ puts -nonewline stderr $exp exit 1 } import { - exec $argv0 import-check <$opt - exec $argv0 import-pipe <$opt + exec $argv0 import-check <$arg + exec $argv0 import-pipe <$arg } path { - if {[file exists $Stash/$opt]} { - puts [file normalize $Stash/$opt] + if {[file exists $Stash/$arg]} { + puts [file normalize $Stash/$arg] } } default {