Skip to content

Commit

Permalink
feat(): introduce 'bpkg source <name>'
Browse files Browse the repository at this point in the history
  • Loading branch information
jwerle committed Mar 23, 2022
1 parent 9ea0f02 commit 1d6eeb6
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 7 deletions.
1 change: 1 addition & 0 deletions bpkg-source
2 changes: 1 addition & 1 deletion lib/install/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ bpkg_install_from_remote () {

## shallow clone
info "Cloning $repo_url to $(pwd)/$name-$version"
git clone "$repo_url" "$name-$version" && (
(test -d "$name-$version" || git clone "$repo_url" "$name-$version") && (
## move into directory
cd "$name-$version" && (
## checkout to branch version or checkout into
Expand Down
44 changes: 39 additions & 5 deletions lib/run/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ usage () {

bpkg_run () {
pushd . >/dev/null || return $?

local should_emit_source=0
local should_source=0
local should_clean=0
local ignore_args=0
local needs_name=0
local package=''
local dest=''
local name=''

for opt in "$@"; do
Expand All @@ -54,9 +59,22 @@ bpkg_run () {

-s|--source)
if (( 0 == ignore_args )); then
# shellcheck disable=SC1090
source "$(which "$name")"
return $?
should_source=1
shift
fi
;;

--emit-source)
if (( 0 == ignore_args )); then
should_emit_source=1
shift
fi
;;

-c|--clean)
if (( 0 == ignore_args )); then
should_clean=1
shift
fi
;;

Expand All @@ -78,7 +96,12 @@ bpkg_run () {
esac
done

local dest=$(bpkg_install --no-prune -g "$1" 2>/dev/null | grep 'info: Cloning' | sed 's/.* to //g' | xargs echo)
if (( 0 == should_clean )); then
dest=$(bpkg_install --no-prune -g "$1" 2>/dev/null | grep 'info: Cloning' | sed 's/.* to //g' | xargs echo)
else
dest=$(bpkg_install -g "$1" 2>/dev/null | grep 'info: Cloning' | sed 's/.* to //g' | xargs echo)
fi


if [ -z "$dest" ]; then return $?; fi

Expand All @@ -90,7 +113,18 @@ bpkg_run () {

shift
popd >/dev/null || return $?
eval "$(which "$name")" $@

if (( 1 == should_emit_source )); then
which "$name"
else
if (( 1 == should_source )); then
# shellcheck disable=SC1090
source "$(which "$name")"
else
eval "$(which "$name")" $@
fi
fi

return $?
}

Expand Down
26 changes: 26 additions & 0 deletions lib/source/source.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

if ! type -f bpkg-run &>/dev/null; then
echo "error: bpkg-run not found, aborting"
exit 1
else
# shellcheck disable=SC2230
# shellcheck source=lib/run/run.sh
source "$(which bpkg-run)"
fi

bpkg_source () {
bpkg_run --emit-source $@
return $?
}

## Use as lib or perform install
if [[ ${BASH_SOURCE[0]} != "$0" ]]; then
export -f bpkg_source
elif validate_parameters; then
bpkg_source "$@"
exit $?
else
#param validation failed
exit $?
fi
13 changes: 13 additions & 0 deletions lib/term/term.sh
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,19 @@ term () {
## main function with args
if [[ ${BASH_SOURCE[0]} != "$0" ]]; then
export -f term
export -f term_dim
export -f term_move
export -f term_reset
export -f term_write
export -f term_clear
export -f term_color
export -f term_blink
export -f term_cursor
export -f term_bright
export -f term_reverse
export -f term_underline
export -f term_transition
export -f term_background
else
term "${@}"
fi
2 changes: 1 addition & 1 deletion setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ if [ -z "$PREFIX" ]; then
fi

# All 'bpkg' supported commands
CMDS="json install package term suggest init utils update list show getdeps run"
CMDS="json install package term suggest init utils update list show getdeps run source"

make_install () {
local source
Expand Down

0 comments on commit 1d6eeb6

Please sign in to comment.