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

EAPI=8

RUST_MIN_VER="1.88.0"

inherit cargo git-r3 shell-completion

DESCRIPTION="Front-end to dev env, polyglot tool manager and task runner"
HOMEPAGE="https://mise.jdx.dev/
	https://github.com/jdx/mise/"

EGIT_REPO_URI="https://github.com/jdx/${PN}"
EGIT_BRANCH="main"

LICENSE="MIT"
SLOT="0"

# "usage" is called by mise binary to generate completions.
BDEPEND="
	dev-util/usage
"

src_unpack() {
	git-r3_src_unpack
	cargo_live_src_unpack
}

src_compile() {
	cargo_src_compile --frozen --verbose --bin "${PN}"
}

src_install() {
	local out_bin="${S}/target/$(usex debug debug release)/${PN}"

	"${out_bin}" trust --all

	local comp=""
	for comp in bash fish zsh ; do
		"${out_bin}" completion "${comp}" > "${PN}.${comp}" || die
	done

	newbashcomp "${PN}.bash" "${PN}"
	dofishcomp "${PN}.fish"
	newzshcomp "${PN}.zsh" "_${PN}"

	cat <<EOF > "${PN}-self-update-instructions.toml" || die
message = "To update ${PN} use emerge -u ${CATEGORY}/${PN} or smart-live-rebuild"
EOF
	insinto "/usr/lib/${PN}"
	doins "${PN}-self-update-instructions.toml"

	dobin "${out_bin}"
	doman "man/man1/${PN}.1"
	einstalldocs
}