# Copyright 2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

# Autogenerated by pycargoebuild 0.16.0

EAPI=8

RUST_MIN_VER="1.88.0"

CRATES=""

inherit cargo shell-completion

DESCRIPTION="Git hook manager and project linting tool"
HOMEPAGE="https://hk.jdx.dev https://github.com/jdx/hk"
SRC_URI="https://github.com/jdx/hk/archive/refs/tags/v${PV}.tar.gz -> ${P}.tar.gz"
SRC_URI+=" https://github.com/0x6d6e647a/mndz-overlay-assets/releases/download/hk-${PV}/hk-${PV}-crates.tar.xz"

LICENSE="MIT"
# Dependent crate licenses
LICENSE+="
	Apache-2.0 BSD CDLA-Permissive-2.0 ISC MIT MPL-2.0 Unicode-3.0 ZLIB
"
SLOT="0"
KEYWORDS="amd64 arm arm64 ~loong ~mips ppc ppc64 ~riscv ~s390 ~sparc x86"
IUSE="bash-completion fish-completion zsh-completion"

DEPEND="sys-libs/zlib"
RDEPEND="
	${DEPEND}
	dev-vcs/git
	bash-completion? ( dev-util/usage )
	fish-completion? ( dev-util/usage )
	zsh-completion? ( dev-util/usage )
"
BDEPEND="
	dev-build/cmake
	virtual/pkgconfig
	bash-completion? ( dev-util/usage )
	fish-completion? ( dev-util/usage )
	zsh-completion? ( dev-util/usage )
"

# rust does not use *FLAGS from make.conf, silence portage warning
QA_FLAGS_IGNORED="usr/bin/hk"

src_configure() {
	# Skip the generate-docs helper binary
	cargo_src_configure --bin hk
}

src_install() {
	cargo_src_install
	dodoc README.md CHANGELOG.md

	# Completions are generated via the external usage CLI (jdx/usage).
	# Put the just-installed hk on PATH for --usage-cmd.
	local -x PATH="${ED}/usr/bin:${PATH}"

	if use bash-completion; then
		usage g completion bash hk --usage-cmd "hk usage" > hk.bash ||
			die 'Unable to generate bash completions'
		newbashcomp hk.bash hk
	fi
	if use fish-completion; then
		usage g completion fish hk --usage-cmd "hk usage" > hk.fish ||
			die 'Unable to generate fish completions'
		newfishcomp hk.fish hk.fish
	fi
	if use zsh-completion; then
		usage g completion zsh hk --usage-cmd "hk usage" > hk.zsh ||
			die 'Unable to generate zsh completions'
		newzshcomp hk.zsh _hk
	fi
}