task 命令支持给脚本传参,使用 -- 分割,后面的参数都会传给脚本

例如 task x.js -n whyour,脚本就能接收到参数 -n whyour
This commit is contained in:
whyour
2023-10-14 21:47:46 +08:00
parent 5055045d22
commit 9fb9b3d121
7 changed files with 117 additions and 79 deletions
+8 -8
View File
@@ -105,7 +105,7 @@ run_normal() {
file_param=${file_param/$relative_path\//}
fi
$timeoutCmd $which_program $file_param
$timeoutCmd $which_program $file_param "${script_params[@]}"
}
## 并发执行时,设定的 RandomDelay 不会生效,即所有任务立即执行
@@ -147,7 +147,7 @@ run_concurrent() {
for i in "${!array[@]}"; do
export "${env_param}=${array[i]}"
single_log_path="$dir_log/$log_dir/${single_log_time}_$((i + 1)).log"
eval $timeoutCmd $which_program $file_param &>$single_log_path &
eval $timeoutCmd $which_program $file_param "${script_params[@]}" &>$single_log_path &
done
wait
@@ -190,7 +190,7 @@ run_designated() {
cd ${relative_path}
file_param=${file_param/$relative_path\//}
fi
$timeoutCmd $which_program $file_param
$timeoutCmd $which_program $file_param "${script_params[@]}"
}
## 运行其他命令
@@ -241,8 +241,8 @@ main() {
fi
}
handle_task_start "$@"
run_task_before "$@"
main "$@"
run_task_after "$@"
handle_task_end "$@"
handle_task_start "${task_shell_params[@]}"
run_task_before "${task_shell_params[@]}"
main "${task_shell_params[@]}"
run_task_after "${task_shell_params[@]}"
handle_task_end "${task_shell_params[@]}"
+17 -2
View File
@@ -95,6 +95,21 @@ format_params() {
fi
fi
# params=$(echo "$@" | sed -E 's/([^ ])&([^ ])/\1\\\&\2/g')
# 分割 task 内置参数和脚本参数
task_shell_params=()
script_params=()
found_double_dash=false
for arg in "$@"; do
if $found_double_dash; then
script_params+=("$arg")
elif [ "$arg" == "--" ]; then
found_double_dash=true
else
task_shell_params+=("$arg")
fi
done
}
init_begin_time() {
@@ -119,8 +134,8 @@ if [[ $max_time ]]; then
fi
format_params "$@"
define_program "$@"
handle_log_path "$@"
define_program "${task_shell_params[@]}"
handle_log_path "${task_shell_params[@]}"
init_begin_time
eval . $dir_shell/otask.sh "$cmd"