2
0
mirror of https://github.com/bpkg/bpkg synced 2024-11-16 00:12:52 +00:00
bpkg/bpkg.sh

61 lines
798 B
Bash
Raw Normal View History

2014-05-22 19:52:55 +00:00
#!/bin/bash
VERSION="0.0.1"
## output error to stderr
error () {
printf >&2 "error: %s\n" "${@}"
}
## output usage
usage () {
echo "usage: bpkg [-hV] <command> [args]"
}
## feature tests
features () {
if ! type bpkg-json > /dev/null 2>&1; then
error "Missing json parser dependency"
exit 1
fi
}
bpkg () {
local arg="$1"
local cmd=""
shift
case "${arg}" in
## flags
-V|--version)
echo "${VERSION}"
return 0
;;
-h|--help)
usage
return 0
;;
*)
cmd="bpkg-${arg}"
if type -f "${cmd}" > /dev/null 2>&1; then
"${cmd}" "${@}"
return $?
fi
;;
esac
}
## test for required features
features
if [[ ${BASH_SOURCE[0]} != $0 ]]; then
export -f bpkg
else
bpkg "${@}"
exit $?
fi