99# since these functions must only be called in a fresh Bash context
1010
1111main.basalt-package-init () {
12+ # All files are already sourced when testing. This ensures stubs are not overriden
13+ if [ " $BASALT_IS_TESTING " != ' yes' ]; then
14+ if [ -z " $__basalt_dirname " ]; then
15+ printf ' %s\n' " Fatal: main.basalt: Variable '__basalt_dirname' is empty"
16+ exit 1
17+ fi
18+ source " $__basalt_dirname /pkg/src/util/util-init.sh"
19+ fi
20+
1221# Set main variables (WET)
1322local basalt_global_repo=
1423if [ -L " $0 " ]; then # Only subshell when necessary
@@ -22,79 +31,80 @@ main.basalt-package-init() {
2231fi
2332basalt_global_repo=${basalt_global_repo%/* } ; basalt_global_repo=${basalt_global_repo%/* }
2433
25- cat << EOF
26- basalt.package-init() {
27- # basalt variables
28- export BASALT_GLOBAL_REPO="$basalt_global_repo "
29- EOF
30- cat << "EOF "
31- export BASALT_GLOBAL_DATA_DIR="${BASALT_GLOBAL_DATA_DIR:-"${XDG_DATA_HOME:-$HOME/.local/share}/basalt"}"
34+ util.init_print_package_init " $basalt_global_repo "
35+ # cat <<EOF
36+ # basalt.package-init() {
37+ # # basalt variables
38+ # export BASALT_GLOBAL_REPO="$basalt_global_repo"
39+ # EOF
40+ # cat <<"EOF"
41+ # export BASALT_GLOBAL_DATA_DIR="${BASALT_GLOBAL_DATA_DIR:-"${XDG_DATA_HOME:-$HOME/.local/share}/basalt"}"
3242
33- if [ -z "$BASALT_GLOBAL_DATA_DIR" ]; then
34- printf '%s\n' "Error: basalt.package-init: Variable '\$BASALT_GLOBAL_DATA_DIR' is empty" >&2
35- exit 1
36- fi
43+ # if [ -z "$BASALT_GLOBAL_DATA_DIR" ]; then
44+ # printf '%s\n' "Error: basalt.package-init: Variable '\$BASALT_GLOBAL_DATA_DIR' is empty" >&2
45+ # exit 1
46+ # fi
3747
38- # basalt global and internal functions
39- if [ ! -f "$BASALT_GLOBAL_REPO/pkg/src/public/basalt-global.sh" ]; then
40- printf '%s\n' "Error: basalt.package-init: Failed to find file 'basalt-global.sh' in '\$BASALT_GLOBAL_REPO'" >&2
41- exit 1
42- fi
43- source "$BASALT_GLOBAL_REPO/pkg/src/public/basalt-global.sh"
48+ # # basalt global and internal functions
49+ # if [ ! -f "$BASALT_GLOBAL_REPO/pkg/src/public/basalt-global.sh" ]; then
50+ # printf '%s\n' "Error: basalt.package-init: Failed to find file 'basalt-global.sh' in '\$BASALT_GLOBAL_REPO'" >&2
51+ # exit 1
52+ # fi
53+ # source "$BASALT_GLOBAL_REPO/pkg/src/public/basalt-global.sh"
4454
45- if [ ! -f "$BASALT_GLOBAL_REPO/pkg/src/public/basalt-package.sh" ]; then
46- printf '%s\n' "Error: basalt.package-init: Failed to find file 'basalt-package.sh' in '\$BASALT_GLOBAL_REPO'" >&2
47- exit 1
48- fi
49- source "$BASALT_GLOBAL_REPO/pkg/src/public/basalt-package.sh"
55+ # if [ ! -f "$BASALT_GLOBAL_REPO/pkg/src/public/basalt-package.sh" ]; then
56+ # printf '%s\n' "Error: basalt.package-init: Failed to find file 'basalt-package.sh' in '\$BASALT_GLOBAL_REPO'" >&2
57+ # exit 1
58+ # fi
59+ # source "$BASALT_GLOBAL_REPO/pkg/src/public/basalt-package.sh"
5060
51- if [ -z "${BASALT_PACKAGE_DIR:-}" ]; then
52- local __old_cd="$PWD"
61+ # if [ -z "${BASALT_PACKAGE_DIR:-}" ]; then
62+ # local __old_cd="$PWD"
5363
54- # Do not use "$0", since it won't work in some environments, such as Bats
55- local __basalt_file="${BASH_SOURCE[0]}"
56- if [ -L "$__basalt_file" ]; then
57- local __basalt_target="$(readlink "$__basalt_file")"
58- if ! cd "${__basalt_target%/*}"; then
59- printf '%s\n' "Error: basalt.package-init: Could not cd to '${__basalt_target%/*}'" >&2
60- exit 1
61- fi
62- else
63- if ! cd "${__basalt_file%/*}"; then
64- printf '%s\n' "Error: basalt.package-init: Could not cd to '${__basalt_file%/*}'" >&2
65- exit 1
66- fi
67- fi
64+ # # Do not use "$0", since it won't work in some environments, such as Bats
65+ # local __basalt_file="${BASH_SOURCE[0]}"
66+ # if [ -L "$__basalt_file" ]; then
67+ # local __basalt_target="$(readlink "$__basalt_file")"
68+ # if ! cd "${__basalt_target%/*}"; then
69+ # printf '%s\n' "Error: basalt.package-init: Could not cd to '${__basalt_target%/*}'" >&2
70+ # exit 1
71+ # fi
72+ # else
73+ # if ! cd "${__basalt_file%/*}"; then
74+ # printf '%s\n' "Error: basalt.package-init: Could not cd to '${__basalt_file%/*}'" >&2
75+ # exit 1
76+ # fi
77+ # fi
6878
69- # Note that this variable should not be exported. It can cause weird things to occur. For example,
70- # if a Basalt local package called a command from a global package, things won't work since
71- # 'BASALT_PACKAGE_DIR' would already be defined and won't be properly set for the global package
72- if ! BASALT_PACKAGE_DIR="$(
73- while [ ! -f 'basalt.toml' ] && [ "$PWD" != / ]; do
74- if ! cd ..; then
75- exit 1
76- fi
77- done
79+ # # Note that this variable should not be exported. It can cause weird things to occur. For example,
80+ # # if a Basalt local package called a command from a global package, things won't work since
81+ # # 'BASALT_PACKAGE_DIR' would already be defined and won't be properly set for the global package
82+ # if ! BASALT_PACKAGE_DIR="$(
83+ # while [ ! -f 'basalt.toml' ] && [ "$PWD" != / ]; do
84+ # if ! cd ..; then
85+ # exit 1
86+ # fi
87+ # done
7888
79- if [ "$PWD" = / ]; then
80- exit 1
81- fi
89+ # if [ "$PWD" = / ]; then
90+ # exit 1
91+ # fi
8292
83- printf '%s' "$PWD"
84- )"; then
85- printf '%s\n' "Error: basalt.package-init: Could not find basalt.toml" >&2
86- if ! cd "$__old_cd"; then
87- printf '%s\n' "Error: basalt.package-init: Could not cd back to '$__old_cd'" >&2
88- exit 1
89- fi
90- exit 1
91- fi
93+ # printf '%s' "$PWD"
94+ # )"; then
95+ # printf '%s\n' "Error: basalt.package-init: Could not find basalt.toml" >&2
96+ # if ! cd "$__old_cd"; then
97+ # printf '%s\n' "Error: basalt.package-init: Could not cd back to '$__old_cd'" >&2
98+ # exit 1
99+ # fi
100+ # exit 1
101+ # fi
92102
93- if ! cd "$__old_cd"; then
94- printf '%s\n' "Error: basalt.package-init: Could not cd back to '$__old_cd'" >&2
95- exit 1
96- fi
97- fi
98- }
99- EOF
103+ # if ! cd "$__old_cd"; then
104+ # printf '%s\n' "Error: basalt.package-init: Could not cd back to '$__old_cd'" >&2
105+ # exit 1
106+ # fi
107+ # fi
108+ # }
109+ # EOF
100110}
0 commit comments