Skip to content

Commit

Permalink
get-installer: fix configuration scripts not retrieving installers
Browse files Browse the repository at this point in the history
also fix performance by only checking for sd if we need it
  • Loading branch information
balupton committed Sep 4, 2023
1 parent d7a3b11 commit ac88cd3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
19 changes: 7 additions & 12 deletions commands/get-installer
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ function get_installer() (
Exit on the first failure, skipping later utilities.
--quiet
Do not output anything.
If invoke, forwarded to installer.
Otherwise, used to suppress missing installer error.
EOF
if test "$#" -ne 0; then
echo-error "$@"
Expand Down Expand Up @@ -379,11 +380,6 @@ function get_installer() (
help "No <items> were specified."
fi

# =====================================
# Dependencies

setup-util-sd --quiet --optional

# =====================================
# Action

Expand All @@ -396,13 +392,14 @@ function get_installer() (
# trim tap prefix
# clementtsang/bottom/bottom => bottom
util="${util##*/}"
# trim flags, and fix up superflous spaces at the start and end
# --classic code --classic => code
if command-exists sd; then
# if util has a space character, then it must have flags or superflous spaces, trim them
if [[ $util == *' '* ]]; then
# --classic code --classic => code
# (^| ) matches either start of the line, or a space character
# [-][^ ]+ matches a dash followed by one or more non-space characters
# so this is what converts the `--classic` flag into ``
# then we trim whitespace at the start and end
setup-util-sd --quiet
util="$(sd '(^| )[-][^ ]+' '' <<<"$util" | sd '^\s+|\s+$' '')"
fi

Expand All @@ -428,9 +425,7 @@ function get_installer() (
return 1
fi
elif test "$option_invoke" = 'no'; then
if test "$option_quiet" != 'yes'; then
print_line "$installer"
fi
print_line "$installer"
if test "$option_first_success" = 'yes'; then
return 0
fi
Expand Down
4 changes: 2 additions & 2 deletions commands/setup-mac-brew
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ function setup_mac_brew() (
# update our listings appropriatley
local item installer
for item in "${requested_formulas[@]}"; do
installer="$(get-installer --first-success --quiet "$item" || :)"
installer="$(get-installer --quiet -- "$item" || :)"
if test -n "$installer"; then
if [[ $installer == 'setup-util-'* ]]; then
SETUP_UTILS+=("${installer#*setup-util-}")
Expand All @@ -650,7 +650,7 @@ function setup_mac_brew() (
HOMEBREW_FORMULAS+=("$item")
done
for item in "${requested_cask[@]}"; do
installer="$(get-installer --first-success --quiet "$item" || :)"
installer="$(get-installer --quiet -- "$item" || :)"
if test -n "$installer"; then
if [[ $installer == 'setup-util-'* ]]; then
SETUP_UTILS+=("${installer:11}")
Expand Down
2 changes: 1 addition & 1 deletion sources/config.bash
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function prepare_packages {

# remove inputs with dedicated installers
for item in "${inputs[@]}"; do
installer="$(get-installer --first-success --quiet -- "$item" || :)"
installer="$(get-installer --quiet -- "$item" || :)"
if test -n "$installer"; then
if [[ $installer == 'setup-util-'* ]]; then
util="${installer#*setup-util-}"
Expand Down

0 comments on commit ac88cd3

Please sign in to comment.