Skip to content

Commit fe6674a

Browse files
committed
feat: Add 'run' subcommand
This is only makes sense for 'local' packages
1 parent d4ca893 commit fe6674a

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

pkg/lib/cmd/basalt.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ basalt.main() {
3636
add) shift; do-add "$@" ;;
3737
remove) shift; do-remove "$@" ;;
3838
install) shift; do-install "$@" ;;
39+
run) shift; do-run "$@" ;;
3940
complete) shift; do-complete "$@" ;;
4041
global) shift
4142
case "$1" in

pkg/lib/commands/do-run.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# shellcheck shell=bash
2+
3+
do-run() {
4+
util.init_local
5+
6+
local -a args=()
7+
for arg; do case "$arg" in
8+
-*)
9+
print.die "Flag '$arg' not recognized"
10+
;;
11+
*)
12+
args+=("$arg")
13+
;;
14+
esac done
15+
16+
if ((${#args[@]} > 1)); then
17+
newindent.die "The only argument must be the executable name"
18+
fi
19+
20+
local bin_name="${args[0]}"
21+
local bin_file="$BASALT_LOCAL_PROJECT_DIR/.basalt/bin/$bin_name"
22+
if [ -x "$bin_file" ]; then
23+
exec "$bin_file"
24+
elif [ -f "$bin_file" ]; then
25+
newindent.die "File '$bin_name' is found, but the package providing it has not made it executable"
26+
else
27+
newindent.die "No executable called '$bin_name' was found"
28+
fi
29+
}

pkg/lib/util/util.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@ Local subcommands:
360360
list [--fetch] [--format=<simple>] [package...]
361361
Lists particular dependencies for the current local project
362362
363+
run <command>
364+
Runs a particular command from any particular locally installed package
365+
363366
Global subcommands:
364367
init <shell>
365368
Prints shell code that must be evaluated during shell

0 commit comments

Comments
 (0)