Skip to content

Commit

Permalink
command-working: give details on failure, setup-util-deno: update for…
Browse files Browse the repository at this point in the history
  • Loading branch information
balupton committed Sep 15, 2024
1 parent bb507bd commit 818d5c0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
33 changes: 26 additions & 7 deletions commands/command-working
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function command_working() (

# https://github.com/greymd/teip/issues/29
# https://trunkcommunity.slack.com/archives/C0205B6KK8X/p1661601215325159
local exceptions=(
local failures=() exceptions=(
ksh
rpi-update
ssh-askpass
Expand All @@ -68,7 +68,7 @@ function command_working() (
trunk
)
function check_status {
local cmd=() command_exit_status
local cmd=() cmd_string cmd_exit_status cmd_output
# ensure sbin commands work
if [[ $* == *sbin* ]] || test "$option_sudo" = 'yes'; then
cmd+=(
Expand All @@ -80,21 +80,33 @@ function command_working() (
# continue with the comand
cmd+=("$@")
# run the command hiding the output
eval_capture --statusvar=command_exit_status --no-output -- "${cmd[@]}"
eval_capture --statusvar=cmd_exit_status --outputvar=cmd_output -- "${cmd[@]}"
# check for correct failure codes
if test "$command_exit_status" -eq 22 -o "$command_exit_status" -eq 200; then
if test "$cmd_exit_status" -eq 22 -o "$cmd_exit_status" -eq 200; then
return 0
else
# otherwise return success or failure code
return "$command_exit_status"
cmd_string="$(echo-escape-command -- "${cmd[@]}")"
if test -n "$cmd_output"; then
cmd_output+=$'\n'
fi
failures+=("$(
echo-style --element+red="$cmd_string" $'\n' "$cmd_output" --/element+red="$cmd_string" --status="$cmd_exit_status"
)")
return "$cmd_exit_status"
fi
}
function check_working {
# reset debug
failures=()

# check it exists first
local cmd
local cmd cmd_string
cmd_string="$(echo-escape-command -- "$1")"
cmd="$(type -P "$1" 2>/dev/null || :)"
if test -z "$cmd"; then
# we must at least find it
echo-style --element/+red="$cmd_string" --status=404 ' ' --error='not working because it is missing' >/dev/stderr
return 1
fi

Expand All @@ -110,7 +122,14 @@ function command_working() (
check_status "$cmd" --version ||
check_status "$cmd" version ||
check_status "$cmd" --help ||
check_status "$cmd" -h
check_status "$cmd" -h || {
{
echo-style --element+red="$cmd_string"
__print_lines "${failures[@]}"
echo-style --/element+red="$cmd_string" --status=1 ' ' --error='not working because it is failing'
} >/dev/stderr
return 1 # command not working
}
}

# =====================================
Expand Down
15 changes: 8 additions & 7 deletions commands/setup-util-deno
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,23 @@

# https://github.com/denoland/deno/releases
# deno-aarch64-apple-darwin.zip
# deno-aarch64-unknown-linux-gnu.zip
# deno-x86_64-apple-darwin.zip
# deno-x86_64-pc-windows-msvc.zip
# deno-x86_64-unknown-linux-gnu.zip
# denort-aarch64-apple-darwin.zip
# denort-aarch64-unknown-linux-gnu.zip
# denort-x86_64-apple-darwin.zip
# denort-x86_64-pc-windows-msvc.zip
# denort-x86_64-unknown-linux-gnu.zip

# https://github.com/LukeChannings/deno-arm64/releases
# deno-linux-arm64.zip

# arm64
# https://github.com/denoland/deno/issues/4862
# https://github.com/LukeChannings/deno-arm64
# now mainlined

# https://repology.org/project/deno/versions

Expand Down Expand Up @@ -54,12 +61,6 @@ function setup_util_deno() (
DOWNLOAD_ARCHIVE_GLOB="$2"
)
}
function add_download_option_arm {
options+=(
DOWNLOAD="$(get_github_asset_url "$1" 'LukeChannings/deno-arm64')"
DOWNLOAD_ARCHIVE_GLOB="$2"
)
}
if is-mac; then
if test "$arch" = 'a64'; then
add_download_option 'deno-aarch64-apple-darwin.zip' 'deno'
Expand All @@ -68,7 +69,7 @@ function setup_util_deno() (
fi
elif is-linux; then
if test "$arch" = 'a64'; then
add_download_option_arm 'deno-linux-arm64.zip' 'deno'
add_download_option 'deno-aarch64-unknown-linux-gnu.zip' 'deno'
elif test "$arch" = 'x64'; then
add_download_option 'deno-x86_64-unknown-linux-gnu.zip' 'deno'
fi
Expand Down

0 comments on commit 818d5c0

Please sign in to comment.