Created
August 6, 2024 13:20
-
-
Save vst/3c16bbdd812f22f0e5dce72918b830f5 to your computer and use it in GitHub Desktop.
niv add hackage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
_find_latest_package_version() { | |
_url="https://hackage.haskell.org/package/${1}" | |
curl -sH "Accept: application/json" "${_url}" | | |
jq -r ". | (keys[] | [.]) | @csv" | | |
sed "s/\"//g" | | |
sort -t. -k1,1n -k2,2n -k3,3n -k4,4n | | |
tail -n1 | |
} | |
_find_package_description() { | |
_name="${1}" | |
_version="${2}" | |
_url="https://hackage.haskell.org/package/${_name}-${_version}" | |
curl -sH "Accept: application/json" "${_url}" | |
} | |
_niv_add() { | |
_name="${1}" | |
_version="$(_find_latest_package_version "${_name}")" | |
_json="$(_find_package_description "${_name}" "${_version}")" | |
_author="$(echo "${_json}" | jq -r ".author")" | |
_copyright="$(echo "${_json}" | jq -r ".copyright")" | |
_description="$(echo "${_json}" | jq ".description")" | |
_homepage="$(echo "${_json}" | jq -r ".homepage")" | |
_license="$(echo "${_json}" | jq -r ".license")" | |
_synopsis="$(echo "${_json}" | jq -r ".synopsis")" | |
_uploaded_at="$(echo "${_json}" | jq -r ".uploaded_at")" | |
niv add \ | |
--template "https://hackage.haskell.org/package/<name>-<version>.tar.gz" \ | |
--attribute name="${_name}" \ | |
--attribute author="${_author}" \ | |
--attribute copyright="${_copyright}" \ | |
--attribute description=${_description} \ | |
--attribute homepage="${_homepage}" \ | |
--attribute license="${_license}" \ | |
--attribute synopsis="${_synopsis}" \ | |
--attribute uploaded_at="${_uploaded_at}" \ | |
--version "${_version}" "${_name}" | |
} | |
_niv_add "${1}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment