update: add leaf query

This commit is contained in:
2026-01-17 15:17:42 -05:00
parent caf66028e6
commit 30fed4b734

47
leaf
View File

@@ -2,10 +2,10 @@
set -e set -e
shopt -s inherit_errexit 2>/dev/null || true shopt -s inherit_errexit 2>/dev/null || true
RED_COLOR="\e[1;31m" RED_COLOR=$"\e[1;31m"
PURPLE_COLOR="\e[1;35m" PURPLE_COLOR=$"\e[1;35m"
GREEN_COLOR="\e[1;32m" GREEN_COLOR=$'\e[1;32m'
CLEAR_COLOR="\e[0m" CLEAR_COLOR=$'\e[0m'
_DEF_PARALLEL_JOBS=4 _DEF_PARALLEL_JOBS=4
_ENV_PARALLEL_JOBS="${PARALLEL_JOBS}" _ENV_PARALLEL_JOBS="${PARALLEL_JOBS}"
@@ -102,6 +102,11 @@ main() {
leaf_unpack_package "${_item}" leaf_unpack_package "${_item}"
done done
;; ;;
query)
shift
[[ $# -eq 1 ]] || leaf_error "usage: leaf query <atom-or-name>"
leaf_query "$1"
;;
*) *)
leaf_print_usage leaf_print_usage
;; ;;
@@ -1002,6 +1007,40 @@ leaf_show_package() {
echo -e "License: ${license[@]}\n" echo -e "License: ${license[@]}\n"
} }
leaf_query() {
local q="$1"
local trace_root="${TRACE_DIR:-/var/lib/leaf/trace}"
if ! leaf_find_remove_pkgbuild "$q"; then
leaf_error "${q} cannot found in the leaf installed database."
fi
local pkgbuild_path="${trace_root}/${PKG_PREFIX}/${PKG_NAME}/PKGBUILD"
[[ -f "$pkgbuild_path" ]] || leaf_error "query: missing PKGBUILD: $pkgbuild_path"
[[ -r "$pkgbuild_path" ]] || leaf_error "query: PKGBUILD not readable: $pkgbuild_path"
(
set -euo pipefail
unset pkgname pkgver
# shellcheck disable=SC1090
source "$pkgbuild_path"
local full="${PKG_PREFIX}/${PKG_NAME}"
if [[ -t 1 && -z "${NO_COLOR-}" ]]; then
local BOLD=$'\e[1m'
printf '%s%s%s %s %s%s%s\n' \
"${BOLD}" "${full}" "${CLEAR_COLOR}" \
"${pkgname}" \
"${GREEN_COLOR}" "${pkgver}" "${CLEAR_COLOR}"
else
printf '%s %s %s\n' "${full}" "${pkgname}" "${pkgver}"
fi
)
}
leaf_pack_package() { leaf_pack_package() {
leaf_build_package leaf_build_package
pushd "${srcdir}" > /dev/null 2>&1 pushd "${srcdir}" > /dev/null 2>&1