feat: Show help even on unsupported platforms

This commit is contained in:
Serge Guzik 2019-02-12 22:04:46 +02:00
parent 4a955c78f4
commit 72f5eaff9a

59
warp4j
View File

@ -45,45 +45,19 @@ WIN=windows
# returns this platform ID # returns this platform ID
function get_this_platform() { function get_this_platform() {
case "$(uname -s)" in local this_platform="$(uname -s)"
case $this_platform in
Linux*) echo $LIN ;; Linux*) echo $LIN ;;
Darwin*) echo $MAC ;; Darwin*) echo $MAC ;;
CYGWIN*) echo $WIN ;; CYGWIN*) echo $WIN ;;
MINGW*) echo $WIN ;; MINGW*) echo $WIN ;;
*) *)
echo "Error: Unsupported platform" >&2 echo "Error: Unsupported platform $this_platform" >&2
fail fail
;; ;;
esac esac
} }
THIS_PLATFORM=$(get_this_platform)
# checks if all dependencies are available
function check_deps() {
local deps=("warp-packer" \
"curl" \
"awk" \
"sed")
local missing=()
for d in ${deps[@]}; do
if ! command -v $d &> /dev/null ; then
missing+=($d)
fi
done
if [[ $missing ]]; then
echo -n "Error: Missing dependencies: " >&2
for d in ${missing[@]}; do
echo -n "$d " >&2
done
echo >&2
fail
fi
}
# actually check dependencies
check_deps
# show help if no arguments specified # show help if no arguments specified
if [[ $# -eq 0 ]]; then if [[ $# -eq 0 ]]; then
print_help print_help
@ -152,6 +126,33 @@ while [[ $# -gt 0 ]]; do
done done
set -- "${POSITIONAL[@]}" # restore positional arguments set -- "${POSITIONAL[@]}" # restore positional arguments
THIS_PLATFORM=$(get_this_platform)
# checks if all dependencies are available
function check_deps() {
local deps=("warp-packer" \
"curl" \
"awk" \
"sed")
local missing=()
for d in ${deps[@]}; do
if ! command -v $d &> /dev/null ; then
missing+=($d)
fi
done
if [[ $missing ]]; then
echo -n "Error: Missing dependencies: " >&2
for d in ${missing[@]}; do
echo -n "$d " >&2
done
echo >&2
fail
fi
}
# actually check dependencies
check_deps
# apart from options only one argument is allowed # apart from options only one argument is allowed
if [[ $# -gt 1 ]]; then if [[ $# -gt 1 ]]; then
echo "Error: Too many arguments: $@, expecting only jar name" >&2 echo "Error: Too many arguments: $@, expecting only jar name" >&2