diff --git a/libexec/basher-list b/libexec/basher-list index 776c9cf..64f37e5 100755 --- a/libexec/basher-list +++ b/libexec/basher-list @@ -28,5 +28,40 @@ do echo "$username/$package" else printf "%-30s %-30s\n" "$username/$package" "($(git --git-dir=${BASHER_PACKAGES_PATH}/$username/$package/.git config --get remote.origin.url))" + + # Find and display executables for this package + package_full="$username/$package" + bins=() + + # Check for package.sh file with custom BINS + if [ -e "$BASHER_PACKAGES_PATH/$package_full/package.sh" ]; then + source "$BASHER_PACKAGES_PATH/$package_full/package.sh" + IFS=: read -ra bins <<< "$BINS" + fi + + # If no custom bins, look for executables + if [ -z "$bins" ]; then + if [ -e "$BASHER_PACKAGES_PATH/$package_full/bin" ]; then + bins=("$BASHER_PACKAGES_PATH/$package_full"/bin/*) + bins=("${bins[@]##*/}") + bins=("${bins[@]/#/bin/}") + else + bins=($(find "$BASHER_PACKAGES_PATH/$package_full" -maxdepth 1 -mindepth 1 -perm -u+x -type f -or -type l 2>/dev/null)) + bins=("${bins[@]##*/}") + fi + fi + + # Display executables if any exist + if [ ${#bins[@]} -gt 0 ] && [ -n "${bins[0]}" ]; then + for bin in "${bins[@]}"; do + name="${bin##*/}" + if ${REMOVE_EXTENSION:-false}; then + name="${name%%.*}" + fi + if [ -n "$name" ]; then + echo "- $name" + fi + done + fi fi done diff --git a/tests/basher-list.bats b/tests/basher-list.bats index 88ababe..795887c 100644 --- a/tests/basher-list.bats +++ b/tests/basher-list.bats @@ -23,21 +23,6 @@ load test_helper refute_line "username2/p3" } -@test "list installed packages with verbose flag shows remote URLs" { - mock_clone - create_package username/p1 - create_package username2/p2 - basher-install username/p1 - basher-install username2/p2 - - run basher-list -v - assert_success - # Check that output contains package names in the verbose format - # The format is: package-name (remote-url) - assert_output --regexp "username/p1 +\(${BASHER_ORIGIN_DIR}/username/p1\)" - assert_output --regexp "username2/p2 +\(${BASHER_ORIGIN_DIR}/username2/p2\)" -} - @test "verbose flag with arguments shows usage" { run basher-list -v extra_arg assert_failure @@ -55,3 +40,72 @@ load test_helper assert_success assert_output "" } + +@test "verbose flag shows complete output format for single package" { + mock_clone + create_package username/package + create_exec username/package tool1 + create_exec username/package tool2.sh + basher-install username/package + + run basher-list -v + assert_success + + # Check exact output format + assert_line --index 0 --regexp "username/package +\(${BASHER_ORIGIN_DIR}/username/package\)" + assert_line --index 1 "- tool1" + assert_line --index 2 "- tool2.sh" +} + +@test "verbose flag with multiple packages shows each with executables" { + mock_clone + + # First package with executables + create_package user1/pkg1 + create_exec user1/pkg1 cmd1 + basher-install user1/pkg1 + + # Second package with different executables + create_package user2/pkg2 + create_exec user2/pkg2 cmd2 + create_exec user2/pkg2 cmd3 + basher-install user2/pkg2 + + # Third package without executables + create_package user3/pkg3 + echo "readme" > "$BASHER_ORIGIN_DIR/user3/pkg3/README" + basher-install user3/pkg3 + + run basher-list -v + assert_success + + # Verify all packages are listed + assert_output --partial "user1/pkg1" + assert_output --partial "user2/pkg2" + assert_output --partial "user3/pkg3" + + # Verify executables are shown + assert_output --partial "- cmd1" + assert_output --partial "- cmd2" + assert_output --partial "- cmd3" +} + +@test "verbose flag respects REMOVE_EXTENSION config" { + mock_clone + create_package username/package + create_exec username/package script.sh + create_exec username/package tool.py + set_remove_extension username/package true + basher-install username/package + + run basher-list -v + assert_success + + # Should show names without extensions + assert_output --partial "- script" + assert_output --partial "- tool" + + # Should NOT show the extensions + refute_output --partial "script.sh" + refute_output --partial "tool.py" +}