From f5c3071fbc41a93799629745f501b101dc0c9861 Mon Sep 17 00:00:00 2001 From: sigoden Date: Thu, 13 Feb 2025 09:24:55 +0800 Subject: feat(script): check-deps will prompt user to install dependencies (#165) --- scripts/check-deps.sh | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'scripts') diff --git a/scripts/check-deps.sh b/scripts/check-deps.sh index 8d44988..d4c102b 100755 --- a/scripts/check-deps.sh +++ b/scripts/check-deps.sh @@ -12,7 +12,8 @@ set -e main() { script_path="$argc_script_path" if [[ ! -f "$script_path" ]]; then - _exit "✗ not found $script_path" + echo "✗ not found $script_path" + exit 0 fi ext="${script_path##*.}" if [[ "$script_path" == tools/* ]]; then @@ -39,7 +40,7 @@ check_sh_dependencies() { fi done if [[ -n "${missing_deps}" ]]; then - _exit "✗ missing tools: ${missing_deps[*]}" + echo "✗ missing tools: ${missing_deps[*]}" fi } @@ -47,7 +48,14 @@ check_agent_js_dependencies() { agent_dir="$(dirname "$script_path")" if [[ -f "$agent_dir/package.json" ]]; then npm ls --prefix="$agent_dir" --depth=0 --silent >/dev/null 2>&1 || \ - _exit "✗ missing node modules, FIX: cd $agent_dir && npm install" + { + cmd="cd $agent_dir && npm install" + echo "✗ missing node modules" + read -p "? run \`$cmd\` to fix [Y/n] " choice + if [[ "$choice" == "Y" || "$choice" == "y" || -z "$choice" ]]; then + (eval "$cmd") + fi + } fi } @@ -55,14 +63,16 @@ check_agent_py_dependencies() { agent_dir="$(dirname "$script_path")" if [[ -f "$agent_dir/requirements.txt" ]]; then python <(cat "$agent_dir/requirements.txt" | sed -E -n 's/^([A-Za-z_]+).*/import \1/p') >/dev/null 2>&1 || \ - _exit "✗ missing python modules, FIX: cd $agent_dir && pip install -r requirements.txt" + { + cmd="cd $agent_dir && pip install -r requirements.txt" + echo "✗ missing python modules" + read -p "? run \`$cmd\` to fix [Y/n] " choice + if [[ "$choice" == "Y" || "$choice" == "y" || -z "$choice" ]]; then + (eval "$cmd") + fi + } fi } -_exit() { - echo "$*" >&2 - exit 0 -} - # See more details at https://github.com/sigoden/argc eval "$(argc --argc-eval "$0" "$@")" -- cgit v1.2.3