88
99# Parse arguments and display help if needed
1010eval $(
11- zz_args " Dispatch Utility" $0 " $@ " << - help
11+ ./src/common-utils/_zz_args.sh " Dispatch Utility" $0 " $@ " << - help
1212 - caller caller Caller script path
1313 - subcmd subcmd Target script to execute
14- + params params Remaining arguments passed to the target script
14+ d debug debug Enable debug mode
15+ & params params Remaining arguments passed to the target script
1516 help
1617)
1718
@@ -24,6 +25,12 @@ usage() {
2425 fi
2526}
2627
28+ preserve () {
29+ echo $@ | while read -r line; do
30+ echo \" $line \"
31+ done
32+ }
33+
2734# Determine caller directory and base name
2835caller_basename=$( basename " ${caller} " )
2936caller_dir=$( dirname " ${caller} " )
@@ -38,8 +45,6 @@ if [ -z "${subcmd}" ]; then
3845 exit 1
3946fi
4047
41-
42-
4348# If caller_dir is just the basename (no slash) and file exists in PATH, try to locate
4449if [ " ${caller_dir} " = " ${caller_basename} " ] || [ -z " ${caller_dir} " ]; then
4550 caller_dir=" ."
5257 target=" ${caller_dir} /${name} "
5358fi
5459
60+ echo $( preserve $params )
61+
5562if [ -x " ${target} " ]; then
5663 zz_log i " Dispatching to executable target: ${target} " >&2
57- exec " ${target} " $params
64+ exec " ${target} " $( preserve $ params)
5865elif [ -f " ${target} " ]; then
5966 zz_log i " Dispatching to subshell target: ${target} " >&2
60- exec sh " ${target} " $params
67+ exec sh " ${target} " $( preserve $ params)
6168else
6269 # Nothing found: show help and available utilities in the same directory
6370 zz_log w " No dispatch target found" && usage
0 commit comments