diff --git a/README.md b/README.md index 080d3cf..6b6931e 100644 --- a/README.md +++ b/README.md @@ -61,14 +61,18 @@ The installer uses one of two target prefixes: /usr/local/bin /usr/local/lib /usr/local/libexec +/usr/local/share/man # Locally (your user only) $HOME/.local/bin $HOME/.local/lib $HOME/.local/libexec +$HOME/.local/share/man ``` Make sure the matching `bin` path is on your `PATH`. +If you install local man pages, make sure `$HOME/.local/share/man` is on your +`MANPATH`. Global install needs root/sudo. @@ -107,6 +111,7 @@ project/ .bash internal/ libexec/ # subcommand executables + man/ # optional man pages, for example man/man1/.1 ``` To help create the project structure and other script templates checkout [bashlib-create](https://github.com/JMinyard1335/bashlib-create) @@ -142,4 +147,3 @@ The tests are fail-first and stop at the first failure. If you want to contribute, check [CONTRIBUTING.md](CONTRIBUTING.md) for setup, guidelines, and checklist. - diff --git a/docs/INSTALL.md b/docs/INSTALL.md index 10eeefa..6e824c1 100644 --- a/docs/INSTALL.md +++ b/docs/INSTALL.md @@ -33,6 +33,11 @@ Finally, install it with itself: Use the `--global` flag if you want to install it globally on the system (this requires root). +Projects can include optional man pages in a `man/` directory. Local installs copy +those pages into `$HOME/.local/share/man`; global installs copy them into +`/usr/local/share/man`. If local man pages do not appear in `man `, add the +local man directory to `MANPATH`. + All commands: ```bash @@ -149,4 +154,3 @@ fi While you could just call something like `installer install $var` in your script, it is faster to source. Sourcing the project will give you access to the following API in your code. see [here](API.md) for the full API. - diff --git a/lib/internal/bashlib_install.bash b/lib/internal/bashlib_install.bash index f1ac5fa..24f60e8 100644 --- a/lib/internal/bashlib_install.bash +++ b/lib/internal/bashlib_install.bash @@ -82,6 +82,7 @@ bashlib_install_from_source() { _bashlib_move_to_bin "$source_dir" "$install_dir" "$tool_name" "$debug" || status=1 _bashlib_move_to_lib "$source_dir" "$install_dir" "$tool_name" "$debug" || status=1 _bashlib_move_to_libexec "$source_dir" "$install_dir" "$tool_name" "$debug" || status=1 + _bashlib_move_to_man "$source_dir" "$install_dir" "$tool_name" "$debug" || status=1 return "$status" } @@ -273,7 +274,7 @@ _bashlib_move_to_bin() { mkdir -p -- "$bin_path" || return 1 if [[ -f "$tool_script_path" ]]; then - install -m 755 -t "$bin_path" -- "$tool_script_path" || return 1 + install -m 755 -- "$tool_script_path" "${bin_path}/${tool_name}" || return 1 return 0 fi @@ -356,8 +357,35 @@ _bashlib_move_to_libexec() { } _bashlib_move_to_man() { - echo -e "\e[1;33m[Warn]:\e[0m Not implemented man pages will not be installed with the project." - echo " please see the projects github page for more info and updates." + local tool_path="" install_path="" tool_name="" debug="" + local dest="" + + if [[ "$#" -lt 3 || "$#" -gt 4 ]]; then + echo "_bashlib_move_to_man: Invalid argument count." >&2 + return 1 + fi + + tool_path="$1" + install_path="$2" + tool_name="$3" + debug="${4:-0}" + + _bashlib_check_install_path "$install_path" || return 1 + + if [[ ! -d "$tool_path" ]]; then + echo "_bashlib_move_to_man: Unable to find tool source dir: $tool_path" >&2 + return 1 + fi + + if [[ ! -d "${tool_path}/man" ]]; then + [[ "$debug" -ge 2 ]] && echo "[debug]: No man/ directory for ${tool_name}" + return 0 + fi + + dest="${install_path}/share/man" + mkdir -p -- "$dest" || return 1 + + cp -r -- "${tool_path}/man/." "$dest" || return 1 return 0 } ## END HELPER FUNCTIONS ------------------------------------------------------------------ diff --git a/test/test_lib_install.bash b/test/test_lib_install.bash index 0a1c0f6..7813a77 100755 --- a/test/test_lib_install.bash +++ b/test/test_lib_install.bash @@ -19,6 +19,7 @@ setup_test_env() { mkdir -p "$SRC_ROOT/lib" mkdir -p "$SRC_ROOT/libexec" + mkdir -p "$SRC_ROOT/man/man1" cat > "$SRC_ROOT/tool.toml" < "$SRC_ROOT/libexec/mytool-subcmd" <<'EOF' #!/usr/bin/env bash echo "hello from libexec" +EOF + + cat > "$SRC_ROOT/man/man1/mytool.1" <<'EOF' +.TH MYTOOL 1 +.SH NAME +mytool \- test tool EOF chmod +x "$SRC_ROOT/mytool" @@ -53,6 +60,7 @@ cleanup_test_env() { rm -f "$HOME/.local/bin/mytool" rm -rf "$HOME/.local/lib/mytool" rm -rf "$HOME/.local/libexec/mytool" + rm -f "$HOME/.local/share/man/man1/mytool.1" } # ----------------------------------------------------------------------------- @@ -112,6 +120,23 @@ test_move_to_libexec() { echo -e "\e[1;32m[TEST]:\e[0m move_to_libexec passed" } +test_move_to_man() { + local status="" + + echo "Testing move to man..." + cleanup_test_env + setup_test_env + + _bashlib_move_to_man "$SRC_ROOT" "$HOME/.local" "mytool" 0 > /dev/null 2>&1 + status="$?" + + assert_true "$status" "move_to_man should succeed, got $status" + assert_installed_file "$HOME/.local/share/man/man1/mytool.1" "man page should be copied" + + cleanup_test_env + echo -e "\e[1;32m[TEST]:\e[0m move_to_man passed" +} + test_move_to_bin() { local status="" @@ -148,6 +173,7 @@ test_install_from_source() { assert_installed_file "$HOME/.local/lib/mytool/tool.toml" "installed tool metadata missing" assert_installed_dir "$HOME/.local/libexec/mytool" "installed libexec dir missing" assert_installed_file "$HOME/.local/libexec/mytool/mytool-subcmd" "installed libexec file missing" + assert_installed_file "$HOME/.local/share/man/man1/mytool.1" "installed man page missing" cleanup_test_env echo -e "\e[1;32m[TEST]:\e[0m install_from_source passed" @@ -192,6 +218,7 @@ test_lib_install_main() { test_move_to_lib test_move_to_libexec + test_move_to_man test_move_to_bin test_install_bad_install_path test_install_from_source @@ -203,4 +230,3 @@ test_lib_install_main() { if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then test_lib_install_main "$@" fi -