You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
2.3 KiB
58 lines
2.3 KiB
#JMN 2024 |
|
#A simple wrapper to call the 'zipfs mkimg' (tcl::zipfs::mkimg) command via commandline arguments. |
|
#(avoiding piping commands to tclsh via stdin to make calling simpler, and to provide more specific error messages) |
|
# |
|
set script_title "[file tail [info nameofexecutable]] [file tail [info script]]" |
|
set usage "$script_title -outfile <target_zipfile_path> -indir <folder_to_zip> ?-strip <path_prefix_to_strip>? ?-password <plaintext>? ?-infile <explicit_prepend_file>?" |
|
set arglist $::argv |
|
#informational arglist echo goes to stdout if wanted - stderr output makes zig build |
|
#report the (successful) step with a misleading "failed command:" block (0.16 |
|
#build_runner prints that whenever result_stderr is nonempty, success or not) |
|
puts stdout "====> '$arglist'" |
|
#error 42 |
|
if {![llength $arglist]} { |
|
puts stderr $usage |
|
exit 1 |
|
} |
|
if {[llength $arglist] %2 != 0} { |
|
puts stderr "$script_title error: expected an even number of option value pairs. Got [llength $arglist] commandline arguments. '$arglist'" |
|
puts stderr $usage |
|
exit 2 |
|
} |
|
set known_opts [list -outfile -indir -strip -password -infile] |
|
dict for {k v} $arglist { |
|
switch -exact -- $k { |
|
-outfile - -indir - -strip - -password - -infile {} |
|
default { |
|
puts stderr "$script_title error: unrecognised option $k. Known_options $known_opts" |
|
exit 3 |
|
} |
|
} |
|
} |
|
set defaults [dict create\ |
|
-strip ""\ |
|
-password ""\ |
|
] |
|
|
|
set opts [dict merge $defaults $arglist] |
|
if {![dict exists $opts -outfile]} { |
|
puts stderr "$script_title error: Missing -outfile <zipfilename>" |
|
exit 4 |
|
} |
|
if {![dict exists $opts -indir]} { |
|
puts stderr "$script_title error: Missing -indir <folder>" |
|
exit 5 |
|
} |
|
set callargs [list [file normalize [dict get $opts -outfile]] [file normalize [dict get $opts -indir]] [file normalize [dict get $opts -strip]] [dict get $opts -password]] |
|
if {[dict exists $opts -infile]} { |
|
lappend callargs [file normalize [dict get $opts -infile]] |
|
} |
|
puts stdout "$script_title call 'tcl::zipfs::mkimg $callargs'" ;#stdout: stderr makes zig report the successful step as 'failed command' |
|
|
|
if {[catch { |
|
tcl::zipfs::mkimg {*}$callargs |
|
} errM]} { |
|
puts stderr "$script_title error: Failure during call 'tcl::zipfs::mkimg $callargs'\n $errM" |
|
exit 6 |
|
} |
|
exit 0 |