From acdf40dd2c4b912e9831029b899d3ffb5e92fb46 Mon Sep 17 00:00:00 2001 From: Tw93 Date: Tue, 20 Jan 2026 14:44:11 +0800 Subject: [PATCH] Unify output format for multiple versions check --- lib/clean/dev.sh | 21 ++++++++++----------- tests/dev_extended.bats | 16 ++++++++-------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/lib/clean/dev.sh b/lib/clean/dev.sh index 6146f28..034ffc5 100644 --- a/lib/clean/dev.sh +++ b/lib/clean/dev.sh @@ -77,12 +77,12 @@ clean_dev_rust() { } # Helper: Check for multiple versions in a directory. -# Args: $1=directory, $2=tool_name, $3+=additional_lines +# Args: $1=directory, $2=tool_name, $3=list_command, $4=remove_command check_multiple_versions() { local dir="$1" local tool_name="$2" - shift 2 - local -a additional_lines=("$@") + local list_cmd="${3:-}" + local remove_cmd="${4:-}" if [[ ! -d "$dir" ]]; then return 0 @@ -93,10 +93,11 @@ check_multiple_versions() { if [[ "$count" -gt 1 ]]; then note_activity - echo -e " Found ${GREEN}${count}${NC} ${tool_name}" - for line in "${additional_lines[@]}"; do - echo -e " $line" - done + local hint="" + if [[ -n "$list_cmd" ]]; then + hint=" · ${GRAY}${list_cmd}${NC}" + fi + echo -e " ${YELLOW}${ICON_WARNING}${NC} ${tool_name}: ${count} found${hint}" fi } @@ -107,8 +108,7 @@ check_rust_toolchains() { check_multiple_versions \ "$HOME/.rustup/toolchains" \ "Rust toolchains" \ - "You can list them with: ${GRAY}rustup toolchain list${NC}" \ - "Remove unused with: ${GRAY}rustup toolchain uninstall ${NC}" + "rustup toolchain list" } # Docker caches (guarded by daemon check). clean_dev_docker() { @@ -170,8 +170,7 @@ check_android_ndk() { check_multiple_versions \ "$HOME/Library/Android/sdk/ndk" \ "Android NDK versions" \ - "Manage in: ${GRAY}Android Studio → SDK Manager${NC}" \ - "Or manually at: ${GRAY}\$HOME/Library/Android/sdk/ndk${NC}" + "Android Studio → SDK Manager" } clean_dev_mobile() { diff --git a/tests/dev_extended.bats b/tests/dev_extended.bats index 4496ba1..8747fc0 100644 --- a/tests/dev_extended.bats +++ b/tests/dev_extended.bats @@ -123,29 +123,29 @@ EOF } @test "check_android_ndk reports multiple NDK versions" { - run bash -c 'HOME=$(mktemp -d) && mkdir -p "$HOME/Library/Android/sdk/ndk"/{21.0.1,22.0.0,20.0.0} && source "$0" && note_activity() { :; } && NC="" && GREEN="" && GRAY="" && check_android_ndk' "$PROJECT_ROOT/lib/clean/dev.sh" + run bash -c 'HOME=$(mktemp -d) && mkdir -p "$HOME/Library/Android/sdk/ndk"/{21.0.1,22.0.0,20.0.0} && source "$0" && note_activity() { :; } && NC="" && GREEN="" && GRAY="" && YELLOW="" && ICON_WARNING="●" && check_android_ndk' "$PROJECT_ROOT/lib/clean/dev.sh" [ "$status" -eq 0 ] - [[ "$output" == *"Found 3 Android NDK versions"* ]] + [[ "$output" == *"Android NDK versions: 3 found"* ]] } @test "check_android_ndk silent when only one NDK" { - run bash -c 'HOME=$(mktemp -d) && mkdir -p "$HOME/Library/Android/sdk/ndk/22.0.0" && source "$0" && note_activity() { :; } && NC="" && GREEN="" && GRAY="" && check_android_ndk' "$PROJECT_ROOT/lib/clean/dev.sh" + run bash -c 'HOME=$(mktemp -d) && mkdir -p "$HOME/Library/Android/sdk/ndk/22.0.0" && source "$0" && note_activity() { :; } && NC="" && GREEN="" && GRAY="" && YELLOW="" && ICON_WARNING="●" && check_android_ndk' "$PROJECT_ROOT/lib/clean/dev.sh" [ "$status" -eq 0 ] - [[ "$output" != *"Found"*"NDK"* ]] + [[ "$output" != *"NDK versions"* ]] } @test "check_rust_toolchains reports multiple toolchains" { - run bash -c 'HOME=$(mktemp -d) && mkdir -p "$HOME/.rustup/toolchains"/{stable,nightly,1.75.0}-aarch64-apple-darwin && source "$0" && note_activity() { :; } && NC="" && GREEN="" && GRAY="" && rustup() { :; } && export -f rustup && check_rust_toolchains' "$PROJECT_ROOT/lib/clean/dev.sh" + run bash -c 'HOME=$(mktemp -d) && mkdir -p "$HOME/.rustup/toolchains"/{stable,nightly,1.75.0}-aarch64-apple-darwin && source "$0" && note_activity() { :; } && NC="" && GREEN="" && GRAY="" && YELLOW="" && ICON_WARNING="●" && rustup() { :; } && export -f rustup && check_rust_toolchains' "$PROJECT_ROOT/lib/clean/dev.sh" [ "$status" -eq 0 ] - [[ "$output" == *"Found 3 Rust toolchains"* ]] + [[ "$output" == *"Rust toolchains: 3 found"* ]] } @test "check_rust_toolchains silent when only one toolchain" { - run bash -c 'HOME=$(mktemp -d) && mkdir -p "$HOME/.rustup/toolchains/stable-aarch64-apple-darwin" && source "$0" && note_activity() { :; } && NC="" && GREEN="" && GRAY="" && rustup() { :; } && export -f rustup && check_rust_toolchains' "$PROJECT_ROOT/lib/clean/dev.sh" + run bash -c 'HOME=$(mktemp -d) && mkdir -p "$HOME/.rustup/toolchains/stable-aarch64-apple-darwin" && source "$0" && note_activity() { :; } && NC="" && GREEN="" && GRAY="" && YELLOW="" && ICON_WARNING="●" && rustup() { :; } && export -f rustup && check_rust_toolchains' "$PROJECT_ROOT/lib/clean/dev.sh" [ "$status" -eq 0 ] - [[ "$output" != *"Found"*"Rust"* ]] + [[ "$output" != *"Rust toolchains"* ]] }