aboutsummaryrefslogtreecommitdiff
path: root/run-tools.sh
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-05-25 22:01:06 +0800
committer魏曹先生 <1992414357@qq.com>2026-05-25 22:01:06 +0800
commit17217317eaaf57dd5c39538c115e35ddccb8666d (patch)
tree9f1944b847d5e9d157bbc6a8c496bf8f2e7e1d23 /run-tools.sh
parent979e881762a728661e72efd99bc2b35b3db8c71b (diff)
Restructure docs
add template and interactive tutorial, update tool runner
Diffstat (limited to 'run-tools.sh')
-rwxr-xr-xrun-tools.sh59
1 files changed, 39 insertions, 20 deletions
diff --git a/run-tools.sh b/run-tools.sh
index 7a1062a..c80f9db 100755
--- a/run-tools.sh
+++ b/run-tools.sh
@@ -2,31 +2,50 @@
cd "$(dirname "$0")" || exit 1
+# 收集所有可用工具名称
+tools=()
+
+if [ -d "dev_tools/scripts" ]; then
+ for file in dev_tools/scripts/*.sh; do
+ if [ -f "$file" ]; then
+ tools+=("$(basename "$file" .sh)")
+ fi
+ done
+ for file in dev_tools/scripts/*.py; do
+ if [ -f "$file" ]; then
+ tools+=("$(basename "$file" .py)")
+ fi
+ done
+fi
+if [ -d "dev_tools/src/bin" ]; then
+ for file in dev_tools/src/bin/*.rs; do
+ if [ -f "$file" ]; then
+ tools+=("$(basename "$file" .rs)")
+ fi
+ done
+fi
+
if [ $# -eq 0 ]; then
echo "Available:"
- if [ -d "dev_tools/scripts" ]; then
- for file in dev_tools/scripts/*.sh; do
- if [ -f "$file" ]; then
- basename "$file" .sh
- fi
- done
- for file in dev_tools/scripts/*.py; do
- if [ -f "$file" ]; then
- basename "$file" .py
- fi
- done
- fi
- if [ -d "dev_tools/src/bin" ]; then
- for file in dev_tools/src/bin/*.rs; do
- if [ -f "$file" ]; then
- basename "$file" .rs
- fi
- done
- fi
+ for i in "${!tools[@]}"; do
+ printf " [%2d] %s\n" $((i + 1)) "${tools[$i]}"
+ done
exit 1
fi
target_bin="$1"
+
+# 检查是否输入的是数字
+if [[ "$target_bin" =~ ^[0-9]+$ ]]; then
+ idx=$((target_bin - 1))
+ if [ "$idx" -ge 0 ] && [ "$idx" -lt "${#tools[@]}" ]; then
+ target_bin="${tools[$idx]}"
+ else
+ echo "Error: invalid number '$target_bin', valid range is 1-${#tools[@]}"
+ exit 1
+ fi
+fi
+
target_script="dev_tools/scripts/${target_bin}.sh"
target_python="dev_tools/scripts/${target_bin}.py"
target_file="dev_tools/src/bin/${target_bin}.rs"
@@ -37,7 +56,7 @@ if [ -f "$target_script" ]; then
elif [ -f "$target_python" ]; then
python "$target_python"
elif [ -f "$target_file" ]; then
- cargo run --manifest-path dev_tools/Cargo.toml --bin "$1" --quiet
+ cargo run --manifest-path dev_tools/Cargo.toml --bin "$target_bin" --quiet
else
echo "Error: target '$target_bin' does not exist"
exit 1