Skip to content

Commit 0c3932f

Browse files
committed
path: Search _GO_SCRIPTS_DIR before plugin dirs
Part of #120, and similar to #122, searching the local `_GO_SCRIPT_DIR` before plugin dirs seems like a more natural and scalable model. `_GO_CORE_DIR/libexec` for builtins still comes first. The idea behind this model is that when reading a script within the `./go` script framework, it should be clear that: - core framework scripts are the same everywhere; they can't be shadowed by scripts with the same name - project-local scripts take precedence before any plugin scripts The implications of this last point are that: - a script that is installed as a plugin will find its own scripts before those that share the same name with other installed plugins, avoiding collisions and possibly obscure bugs - the parent project can determine the precedence of plugin scripts sharing the same name, as the plugins can be installed using directory names that force a particular order (e.g. '00-', '01-', '02-' prefixes). - as an alternative to the approach in the preceding point, the parent project can potentially resolve conflicts by installing its own scripts that then delegate to a specific plugin script And to this last point, I've filed #127 to facilitate help text discovery.
1 parent 96fe117 commit 0c3932f

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

lib/internal/path

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if [[ "${#_GO_SEARCH_PATHS[@]}" -eq 0 ]]; then
1313
unset '_GO_PLUGINS_PATHS'
1414
fi
1515
fi
16-
_GO_SEARCH_PATHS+=("${_GO_PLUGINS_PATHS[@]}" "$_GO_SCRIPTS_DIR")
16+
_GO_SEARCH_PATHS+=("$_GO_SCRIPTS_DIR" "${_GO_PLUGINS_PATHS[@]}")
1717
fi
1818

1919
_@go.list_available_commands() {

tests/path/init-constants.bats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ teardown() {
3939

4040
local expected_paths=(
4141
"$_GO_ROOTDIR/libexec"
42-
"${plugin_bindirs[@]}"
43-
"$TEST_GO_SCRIPTS_DIR")
42+
"$TEST_GO_SCRIPTS_DIR"
43+
"${plugin_bindirs[@]}")
4444

4545
assert_line_equals 0 "_GO_PLUGINS_DIR: $TEST_GO_PLUGINS_DIR"
4646
assert_line_equals 1 \

tests/vars.bats

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ quotify_expected() {
8686
"[2]=\"$TEST_GO_PLUGINS_DIR/plugin2/bin\"")
8787
local search_paths=("[0]=\"$TEST_GO_ROOTDIR/bin\""
8888
"[1]=\"$_GO_CORE_DIR/libexec\""
89-
"[2]=\"$TEST_GO_PLUGINS_DIR/plugin0/bin\""
90-
"[3]=\"$TEST_GO_PLUGINS_DIR/plugin1/bin\""
91-
"[4]=\"$TEST_GO_PLUGINS_DIR/plugin2/bin\""
92-
"[5]=\"$TEST_GO_SCRIPTS_DIR\"")
89+
"[2]=\"$TEST_GO_SCRIPTS_DIR\""
90+
"[3]=\"$TEST_GO_PLUGINS_DIR/plugin0/bin\""
91+
"[4]=\"$TEST_GO_PLUGINS_DIR/plugin1/bin\""
92+
"[5]=\"$TEST_GO_PLUGINS_DIR/plugin2/bin\"")
9393

9494
# Note that the `format` module imports `strings` and `validation`.
9595
local expected_modules=('[0]="module_0"'

0 commit comments

Comments
 (0)