feat(): introduce 'bpkg source <name>'

pull/143/head
jwerle 2 years ago committed by Joseph Werle
parent 9ea0f02b76
commit 1d6eeb6529

@ -0,0 +1 @@
lib/source/source.sh

@ -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

@ -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
@ -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
;;
@ -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
@ -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 $?
}

@ -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

@ -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

@ -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

Loading…
Cancel
Save