Skip to content

Commit

Permalink
cmd/formulae.sh: read cached JSON when using API
Browse files Browse the repository at this point in the history
  • Loading branch information
cho-m committed Dec 20, 2022
1 parent 04a61fb commit c679d06
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Library/Homebrew/cmd/formulae.sh
Expand Up @@ -8,5 +8,17 @@
source "${HOMEBREW_LIBRARY}/Homebrew/items.sh"

homebrew-formulae() {
homebrew-items '*\.rb' 'Casks' 's|/Formula/|/|' '^homebrew/core'
local formulae
formulae="$(homebrew-items '*\.rb' 'Casks' 's|/Formula/|/|' '^homebrew/core')"

# HOMEBREW_CACHE is set by brew.sh
# shellcheck disable=SC2154
if [[ -n "${HOMEBREW_INSTALL_FROM_API}" && -f "${HOMEBREW_CACHE}/api/formula.json" ]]
then
local api_formulae
api_formulae="$(ruby -e "require 'json'; JSON.parse(File.read('${HOMEBREW_CACHE}/api/formula.json')).each { |f| puts f['name'] }")"
formulae=$(echo -e "${formulae}\n${api_formulae}" | sort -uf | grep .)
fi

echo "${formulae}"
}

0 comments on commit c679d06

Please sign in to comment.