From e48715a01c6e63e50fda231ecc0c3b2d1213e421 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Thu, 9 Jul 2026 10:22:44 +0200 Subject: feat: _registry_name_from_url helper for nvchecker autodetect Co-Authored-By: Claude Opus 4.8 --- mkhint | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'mkhint') diff --git a/mkhint b/mkhint index 6a0f157..7d4c505 100755 --- a/mkhint +++ b/mkhint @@ -817,6 +817,32 @@ _has_nvchecker_section() { "$NVCHECKER_CONFIG" } +# Extract a package name from a language-registry download URL. +# Args: . Prints the parsed name, or the fallback +# (PRGNAM) when no host-specific pattern matches. +_registry_name_from_url() { + local url="$1" fallback="$2" + case "$url" in + *crates.io/api/v1/crates/*) + # .../crates/NAME/NAME-VER.crate or .../crates/NAME/VER/download + printf '%s' "${url#*crates.io/api/v1/crates/}" | cut -d/ -f1 + return 0 ;; + *rubygems.org/downloads/*) + # /downloads/NAME-VER.gem + local base="${url##*/downloads/}"; base="${base%.gem}" + printf '%s' "${base%-*}" + return 0 ;; + *registry.npmjs.org/*) + # /NAME/-/NAME-VER.tgz (NAME may be @scope/pkg) + printf '%s' "${url#*registry.npmjs.org/}" | sed 's|/-/.*||' + return 0 ;; + *hackage.haskell.org/package/*) + printf '%s' "${url#*hackage.haskell.org/package/}" | cut -d/ -f1 + return 0 ;; + esac + printf '%s' "$fallback" +} + # Append an nvchecker [pkg] section to NVCHECKER_CONFIG, auto-detecting the # source from the package's .info DOWNLOAD/HOMEPAGE. No-op if section exists. add_nvchecker_section() { -- cgit v1.2.3