mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-18 18:56:25 +00:00
Improve test framework: create_file
create_file '-' sends to standard output create_file --label=LABEL create_file passes other options to tfw_createfile
This commit is contained in:
parent
dabd482ad8
commit
4fbaf8865a
@ -2099,19 +2099,37 @@ tfw_multicolumn() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Create a file with the given size (default 0).
|
# Create a file with the given size (default 0).
|
||||||
# Usage: create_file [--append] <path> [<size>]
|
# Usage: create_file [--append] [create_file opts] [--] <path> [<size>]
|
||||||
# where: <size> is of the form Nu
|
# where: if <path> is - then writes to standard output
|
||||||
|
# <size> is of the form Nu
|
||||||
# N is decimal integer
|
# N is decimal integer
|
||||||
# u is one of kKmMgG (k=10^3, K=2^10, m=10^6, M=2^20, g=10^9, G=2^30)
|
# u is one of kKmMgG (k=10^3, K=2^10, m=10^6, M=2^20, g=10^9, G=2^30)
|
||||||
create_file() {
|
create_file() {
|
||||||
local args=("$@")
|
local args=("$@")
|
||||||
case "$1" in
|
local opt_append=false
|
||||||
--append) shift;;
|
local opt_label=
|
||||||
*) rm -f "$1";;
|
local opts=()
|
||||||
esac
|
while [ $# -ne 0 ]; do
|
||||||
local path="$1"
|
case "$1" in
|
||||||
|
--) shift; break;;
|
||||||
|
--append) opt_append=true; shift;;
|
||||||
|
--label=*) opt_label="${1#*=}"; shift;;
|
||||||
|
--*) opts+=("$1"); shift;;
|
||||||
|
*) break;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
local path="${1?}"
|
||||||
local size="$2"
|
local size="$2"
|
||||||
tfw_createfile --label="$path" ${size:+--size=$size} >>"$path" || error "failed command: create_file ${args[*]}"
|
case "$path" in
|
||||||
|
-)
|
||||||
|
tfw_createfile ${opt_label:+--label="$opt_label"} "${opts[@]}" ${size:+--size=$size}
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
[ -z "$opt_label" ] && opt_label="$path"
|
||||||
|
tfw_createfile ${opt_label:+--label="$opt_label"} "${opts[@]}" ${size:+--size=$size} >>"$path"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
[ $? -eq 0 ] || error "failed command: create_file ${args[*]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add quotations to the given arguments to allow them to be expanded intact
|
# Add quotations to the given arguments to allow them to be expanded intact
|
||||||
|
Loading…
Reference in New Issue
Block a user