# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=xh
pkgver=0.23.0
pkgrel=0
pkgdesc="Yet another HTTPie clone"
url="https://github.com/ducaale/xh"
# riscv64: blocked by rust/cargo
# s390x: fails to build terminal_size crate
arch="all !riscv64 !s390x"
license="MIT"
makedepends="
	cargo
	cargo-auditable
	oniguruma-dev
	openssl-dev
	"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="https://github.com/ducaale/xh/archive/v$pkgver/xh-$pkgver.tar.gz"
options="net" # fetch dependencies

# Link with system-provided oniguruma library (instead building from source
# and bundling).
export RUSTONIG_DYNAMIC_LIBONIG=1

_cargo_opts="--frozen --no-default-features --features native-tls"


prepare() {
	default_prepare

	cargo fetch --target="$CTARGET" --locked
}

build() {
	cargo auditable build $_cargo_opts --release
}

check() {
	cargo test $_cargo_opts
}

package() {
	install -D -m755 target/release/$pkgname -t "$pkgdir"/usr/bin/

	ln -s xh "$pkgdir"/usr/bin/xhs

	install -Dm 644 doc/xh.1 "$pkgdir"/usr/share/man/man1/xh.1

	install -Dm 644 completions/xh.bash "$pkgdir"/usr/share/bash-completion/completions/xh
	install -Dm 644 completions/xh.fish "$pkgdir"/usr/share/fish/vendor_completions.d/xh.fish
	install -Dm 644 completions/_xh "$pkgdir"/usr/share/zsh/site-functions/_xh
}

sha512sums="
c92608e0a2c0d074f46a7761b2a2c598a80bf4a1c455509d900d6cc48f2ac3af9f0256921704aa3bb669217c8c42901c08d54ef0573899a0a7df951fbb102b66  xh-0.23.0.tar.gz
"
