Skip to content

Commit 48d6009

Browse files
committed
feat: Support linking more man directories. Closes #26
This extra directory search occurs automatically when specifying a directory to serach along with the automatic man page detection
1 parent 052e3fb commit 48d6009

File tree

3 files changed

+63
-4
lines changed

3 files changed

+63
-4
lines changed

pkg/lib/commands/do-plumbing-link-man.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ do-plumbing-link-man() {
2222
if [ -f "$file" ]; then
2323
symlink_manfile "$file"
2424
elif [ -d "$file" ]; then
25-
:
26-
# TODO: Implement 2
25+
for actualFile in "$file"/*; do
26+
if [ -f "$actualFile" ]; then
27+
symlink_manfile "$actualFile"
28+
fi
29+
done
2730
fi
2831
done
2932
done
@@ -39,7 +42,15 @@ do-plumbing-link-man() {
3942
# the user does not supply any man files/dirs with any config
4043
fallback_symlink_mans() {
4144
for file in "$BPM_PACKAGES_PATH/$package"/{,man/}*; do
42-
symlink_manfile "$file"
45+
if [ -f "$file" ]; then
46+
symlink_manfile "$file"
47+
elif [ -d "$file" ]; then
48+
for actualFile in "$file"/*; do
49+
if [ -f "$actualFile" ]; then
50+
symlink_manfile "$actualFile"
51+
fi
52+
done
53+
fi
4354
done
4455
}
4556

tests/do-plumbing-link-man.bats

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,47 @@ load 'util/init.sh'
1717
assert [ "$(readlink "$BPM_INSTALL_MAN/man2/exec.2")" = "$BPM_PACKAGES_PATH/username/package/man/exec.2" ]
1818
}
1919

20+
@test "manual man dir links subdirs" {
21+
local package="username/package"
22+
23+
test_util.setup_pkg "$package"; {
24+
echo 'manDirs = [ "a_dir" ]' > 'bpm.toml'
25+
# Leave a '_' suffix to directory to be extra flexible
26+
mkdir -p 'a_dir/man1_'
27+
touch 'a_dir/man1_/exec.1'
28+
29+
mkdir -p 'a_dir/man5_'
30+
touch 'a_dir/man5_/execcfg.5'
31+
}; test_util.finish_pkg
32+
test_util.fake_clone "$package"
33+
34+
run do-plumbing-link-man "$package"
35+
36+
assert_success
37+
assert [ "$(readlink "$BPM_INSTALL_MAN/man1/exec.1")" = "$BPM_PACKAGES_PATH/$package/a_dir/man1_/exec.1" ]
38+
assert [ "$(readlink "$BPM_INSTALL_MAN/man5/execcfg.5")" = "$BPM_PACKAGES_PATH/$package/a_dir/man5_/execcfg.5" ]
39+
}
40+
41+
@test "heuristic search links subdirs" {
42+
local package="username/package"
43+
44+
test_util.setup_pkg "$package"; {
45+
# Leave a '_' suffix to directory to be extra flexible
46+
mkdir -p 'man/man1_'
47+
touch 'man/man1_/exec.1'
48+
49+
mkdir -p 'man5_'
50+
touch 'man5_/execcfg.5'
51+
}; test_util.finish_pkg
52+
test_util.fake_clone "$package"
53+
54+
run do-plumbing-link-man "$package"
55+
56+
assert_success
57+
assert [ "$(readlink "$BPM_INSTALL_MAN/man1/exec.1")" = "$BPM_PACKAGES_PATH/$package/man/man1_/exec.1" ]
58+
assert [ "$(readlink "$BPM_INSTALL_MAN/man5/execcfg.5")" = "$BPM_PACKAGES_PATH/$package/man5_/execcfg.5" ]
59+
}
60+
2061
@test "links mans from bpm.toml to prefix/man" {
2162
local package='username/package'
2263

tests/util/test_util.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,14 @@ test_util.readlink() {
4040
test_util.setup_pkg() {
4141
local package="$1"
4242

43-
create_package "$package"
43+
mkdir -p "$BPM_ORIGIN_DIR/$package"
44+
cd "$BPM_ORIGIN_DIR/$package"
45+
46+
git init .
47+
touch 'README.md'
48+
git add .
49+
git commit -m "Initial commit"
50+
4451
cd "$BPM_ORIGIN_DIR/$package"
4552
}
4653

0 commit comments

Comments
 (0)