Skip to content

Commit 2717d99

Browse files
committed
refactor: Rework variables again
Previously, a 'BPM_ROOT' variable would change all other variables, including the ones appended with './source' and './cellar'. The variables that represented the latter two values are the only configurable ones; 'BPM_ROOT' is gone. This also renames some variables
1 parent 44cc368 commit 2717d99

20 files changed

+75
-197
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ See [Installation](./docs/installation.md) and [Getting Started](./docs/getting-
3838
- Local and user-wide package installation
3939
- Configure (optionally) exactly which directories are used for completions, binaries, or man pages
4040
- Works with essentially all popular Bash projects out of the box
41-
- 260+ Tests
41+
- 240+ Tests
4242

4343
## Alternatives Comparison
4444

completions/_bpm.zsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ case $state in
3838
_describe -t commands "gem subcommand" subcommandOptions
3939
;;
4040
(echo)
41-
local -a subcommandOptions=(BPM_ROOT BPM_CELLAR)
41+
local -a subcommandOptions=(BPM_LOCAL_PROJECT_DIR BPM_CELLAR)
4242
_describe -t commands "gem subcommand" subcommandOptions
4343
;;
4444
(init)

completions/bpm.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ _bpm() {
6060
readarray -t COMPREPLY < <(IFS=' ' compgen -W "${subcommandOptions[*]}" -- "$currentWord")
6161
;;
6262
echo)
63-
subcommandOptions=(BPM_ROOT BPM_CELLAR)
63+
subcommandOptions=(BPM_LOCAL_PROJECT_DIR BPM_CELLAR)
6464
readarray -t COMPREPLY < <(IFS=' ' compgen -W "${subcommandOptions[*]}" -- "$currentWord")
6565
;;
6666
init)

completions/bpm.fish

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ set -l subcommandOptions --shh
1313
complete -c $cmd -f -n "__fish_seen_subcommand_from $subcmd" -a "$subcommandOptions"
1414

1515
set subcmd echo
16-
set -l subcommandOptions BPM_ROOT BPM_CELLAR
16+
set -l subcommandOptions BPM_LOCAL_PROJECT_DIR BPM_CELLAR
1717
complete -c $cmd -f -n "__fish_seen_subcommand_from $subcmd" -a "$subcommandOptions"
1818

1919
set subcmd init

docs/reference.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Environment Variables
44

5-
### `BPM_ROOT`
5+
### `BPM_LOCAL_PROJECT_DIR`
66

77
The location of the root `bpm` folder. Defaults to `"${XDG_DATA_HOME:-$HOME/.local/share}/bpm"`
88

@@ -12,7 +12,7 @@ Set to a non-null string to clone the full repository history instead of only th
1212

1313
### `BPM_CELLAR`
1414

15-
Set the installation and package checkout prefix (default is `$BPM_ROOT/cellar`). Setting this to `/usr/local`, for example, will install binaries to `/usr/local/bin`, manpages to `/usr/local/man`, completions to `/usr/local/completions`, and clone packages to `/usr/local/packages`
15+
Set the installation and package checkout prefix (default is `$BPM_LOCAL_PROJECT_DIR/cellar`). Setting this to `/usr/local`, for example, will install binaries to `/usr/local/bin`, manpages to `/usr/local/man`, completions to `/usr/local/completions`, and clone packages to `/usr/local/packages`
1616

1717
## `bpm.toml`
1818

pkg/lib/cmd/bpm-load.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/usr/bin/env bash
22

3+
# TODO: print error if sourcing and passing arguments
4+
# TODO: print error if not being sourced and no arguments are passed
5+
36
# @description Source Bash packages to initialize any functions
47
# that they may want to provide in the global scope
58
# @exitcode 4 Unexpected internal error
@@ -63,11 +66,11 @@ bpm-load() {
6366
unset REPLY REPLY1 REPLY2 REPLY3 REPLY4 REPLY5 # Be extra certain of no clobbering
6467

6568
# Get the bpm root dir (relative to this function's callsite)
66-
local __bpm_root_dir=
69+
local __bpm_cellar=
6770
if [ "$__bpm_flag_global" = yes ]; then
68-
__bpm_root_dir="${BPM_ROOT:-"${XDG_DATA_HOME:-$HOME/.local/share}/bpm"}/cellar"
71+
__bpm_cellar="${BPM_CELLAR:-"${XDG_DATA_HOME:-$HOME/.local/share}/bpm/cellar"}"
6972
else
70-
if ! __bpm_root_dir="$(util.get_project_root_dir)/bpm_packages"; then
73+
if ! __bpm_cellar="$(util.get_project_root_dir)/bpm_packages"; then
7174
printf '%s\n' "bpm-load: Error: Unexpected error calling function 'util.get_project_root_dir' with PWD '$PWD'"
7275
__bpm_bpm_load_restore_options
7376
return 4
@@ -76,7 +79,7 @@ bpm-load() {
7679

7780
# Source file, behavior depending on whether it was specifed
7881
if [ -n "$__bpm_file" ]; then
79-
local __bpm_full_path="$__bpm_root_dir/packages/$__bpm_site/$__bpm_package/$__bpm_file"
82+
local __bpm_full_path="$__bpm_cellar/packages/$__bpm_site/$__bpm_package/$__bpm_file"
8083

8184
if [ -d "$__bpm_full_path" ]; then
8285
printf '%s\n' "bpm-load: Error: '$__bpm_full_path' is a directory"
@@ -97,7 +100,7 @@ bpm-load() {
97100
local __bpm_file= __bpm_file_was_sourced='no'
98101
# shellcheck disable=SC2041
99102
for __bpm_file in 'load.bash'; do
100-
local __bpm_full_path="$__bpm_root_dir/packages/$__bpm_site/$__bpm_package/$__bpm_file"
103+
local __bpm_full_path="$__bpm_cellar/packages/$__bpm_site/$__bpm_package/$__bpm_file"
101104

102105
if [ -f "$__bpm_full_path" ]; then
103106
__bpm_file_was_sourced='yes'

pkg/lib/cmd/bpm.sh

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,26 @@ set -ETeo pipefail
44
shopt -s nullglob extglob
55

66
main() {
7-
: "${BPM_ROOT:="${XDG_DATA_HOME:-$HOME/.local/share}/bpm"}"
8-
: "${BPM_CELLAR:="$BPM_ROOT/cellar"}"
9-
: "${BPM_PACKAGES_PATH:="$BPM_CELLAR/packages"}"
10-
: "${BPM_INSTALL_BIN:="$BPM_CELLAR/bin"}"
11-
: "${BPM_INSTALL_MAN:="$BPM_CELLAR/man"}"
12-
: "${BPM_INSTALL_COMPLETIONS:="$BPM_CELLAR/completions"}"
13-
147
for f in "$PROGRAM_LIB_DIR"/{commands,util}/?*.sh; do
158
source "$f"
169
done
1710

11+
if [ "$1" = init ] || [[ "$1" = - && "$2" = init ]]; then
12+
shift
13+
do-init "$@"
14+
return
15+
fi
16+
17+
if [[ -z "$BPM_REPO_SOURCE" || -z "$BPM_CELLAR" ]]; then
18+
die "Either 'BPM_REPO_SOURCE' or 'BPM_CELLAR' is empty. Did you forget to run add \`bpm init <shell>\` in your shell configuration?"
19+
fi
20+
21+
# 'BPM_LOCAL_PROJECT_DIR' is set in 'util.setup_mode'
22+
BPM_PACKAGES_PATH="$BPM_CELLAR/packages"
23+
BPM_INSTALL_BIN="$BPM_CELLAR/bin"
24+
BPM_INSTALL_MAN="$BPM_CELLAR/man"
25+
BPM_INSTALL_COMPLETIONS="$BPM_CELLAR/completions"
26+
1827
BPM_MODE='local'
1928

2029
for arg; do

pkg/lib/commands/do-add.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ do-add() {
4545
fi
4646

4747
if [ "$flag_all" = yes ]; then
48-
local bpm_toml_file="$BPM_ROOT/bpm.toml"
48+
local bpm_toml_file="$BPM_LOCAL_PROJECT_DIR/bpm.toml"
4949

5050
if util.get_toml_array "$bpm_toml_file" 'dependencies'; then
5151
log.info "Adding all dependencies"

pkg/lib/commands/do-echo.sh

Lines changed: 0 additions & 7 deletions
This file was deleted.

pkg/lib/commands/do-init.sh

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
echo_bpm_variables_posix() {
44
cat <<-EOF
55
# bpm variables
6-
export BPM_REPO_ROOT="$BPM_REPO_ROOT"
7-
export BPM_CELLAR="$BPM_CELLAR"
6+
export BPM_REPO_SOURCE="${BPM_REPO_SOURCE:-"${XDG_DATA_HOME:-$HOME/.local/share}/bpm/source"}"
7+
export BPM_CELLAR="${BPM_CELLAR:-"${XDG_DATA_HOME:-$HOME/.local/share}/bpm/cellar"}"
88
99
EOF
1010
}
1111

1212
echo_bpm_include_posix() {
1313
cat <<-"EOF"
1414
# bpm include function
15-
if [ -f "$BPM_REPO_ROOT/pkg/share/include.sh" ]; then
16-
. "$BPM_REPO_ROOT/pkg/share/include.sh"
15+
if [ -f "$BPM_REPO_SOURCE/pkg/share/include.sh" ]; then
16+
. "$BPM_REPO_SOURCE/pkg/share/include.sh"
1717
fi
1818
1919
EOF
@@ -51,15 +51,15 @@ do-init() {
5151
fish)
5252
cat <<-EOF
5353
# bpm variables
54-
set -gx BPM_REPO_ROOT $BPM_REPO_ROOT
55-
set -gx BPM_CELLAR $BPM_CELLAR
54+
set -gx BPM_REPO_SOURCE "${BPM_REPO_SOURCE:-"${XDG_DATA_HOME:-$HOME/.local/share}/bpm/source"}"
55+
set -gx "${BPM_CELLAR:-"${XDG_DATA_HOME:-$HOME/.local/share}/bpm/cellar"}"
5656
5757
# bpm completion
58-
source \$BPM_REPO_ROOT/completions/bpm.fish
58+
source \$BPM_REPO_SOURCE/completions/bpm.fish
5959
6060
# bpm include function
61-
if [ -f "$BPM_REPO_ROOT/pkg/share/include.fish" ]
62-
source "$BPM_REPO_ROOT/pkg/share/include.fish"
61+
if [ -f "$BPM_REPO_SOURCE/pkg/share/include.fish" ]
62+
source "$BPM_REPO_SOURCE/pkg/share/include.fish"
6363
end
6464
6565
# bpm packages PATH
@@ -80,8 +80,8 @@ do-init() {
8080
echo_bpm_variables_posix
8181
cat <<-EOF
8282
# bpm completions
83-
if [ -f "\$BPM_REPO_ROOT/completions/bpm.bash" ]; then
84-
. "\$BPM_REPO_ROOT/completions/bpm.bash"
83+
if [ -f "\$BPM_REPO_SOURCE/completions/bpm.bash" ]; then
84+
. "\$BPM_REPO_SOURCE/completions/bpm.bash"
8585
fi
8686
8787
EOF
@@ -103,7 +103,7 @@ do-init() {
103103
echo_bpm_variables_posix
104104
cat <<-EOF
105105
# bpm completions
106-
fpath=("\$BPM_REPO_ROOT/completions" \$fpath)
106+
fpath=("\$BPM_REPO_SOURCE/completions" \$fpath)
107107
EOF
108108

109109
echo_bpm_include_posix

pkg/lib/commands/do-remove.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ do-remove() {
3737
fi
3838

3939
if [ "$flag_all" = yes ]; then
40-
local bpm_toml_file="$BPM_ROOT/bpm.toml"
40+
local bpm_toml_file="$BPM_LOCAL_PROJECT_DIR/bpm.toml"
4141

4242
if util.get_toml_array "$bpm_toml_file" 'dependencies'; then
4343
log.info "Removing all dependencies"

pkg/lib/commands/do-upgrade.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ do-upgrade() {
6262

6363
# TODO: test this
6464
if [ "$flag_all" = yes ]; then
65-
local bpm_toml_file="$BPM_ROOT/bpm.toml"
65+
local bpm_toml_file="$BPM_LOCAL_PROJECT_DIR/bpm.toml"
6666

6767
if util.get_toml_array "$bpm_toml_file" 'dependencies'; then
6868
log.info "Adding all dependencies"

pkg/lib/util/util.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,9 @@ util.setup_mode() {
277277
printf " -> %s\n" "'$project_root_dir'"
278278
fi
279279

280-
BPM_ROOT="$project_root_dir"
280+
# Set the variables as to make them orrect for 'local' mode
281+
BPM_LOCAL_PROJECT_DIR="$project_root_dir"
282+
BPM_REPO_SOURCE="$BPM_REPO_SOURCE"
281283
BPM_CELLAR="$project_root_dir/bpm_packages"
282284
BPM_PACKAGES_PATH="$BPM_CELLAR/packages"
283285
BPM_INSTALL_BIN="$BPM_CELLAR/bin"

tests/bpm-load.bats

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ load 'util/init.sh'
66
local site='github.com'
77
local pkg="user/project2"
88

9+
BPM_REPO_SOURCE="$BPM_TEST_REPO_ROOT/../source"
10+
BPM_CELLAR="$BPM_TEST_DIR/cellar"
11+
912
test_util.setup_pkg "$pkg"; {
1013
echo "printf '%s\n' 'it works :)'" > 'load.bash'
1114
}; test_util.finish_pkg

tests/do-echo.bats

Lines changed: 0 additions & 137 deletions
This file was deleted.

0 commit comments

Comments
 (0)