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

EAPI=8

inherit go-module

DESCRIPTION="Simple and configurable vulnerability scanner based on YAML templates"
HOMEPAGE="https://github.com/projectdiscovery/nuclei https://projectdiscovery.io"
SRC_URI="https://github.com/projectdiscovery/${PN}/archive/refs/tags/v${PV}.tar.gz -> ${P}.gh.tar.gz"
S="${WORKDIR}/${PN}-${PV}"

LICENSE="MIT"
SLOT="0"
KEYWORDS="~amd64"

# Go module deps are fetched at build time rather than vendored, so the build
# needs network access; the test suite also reaches the network. RESTRICT grants
# it for this package alone, regardless of the user's FEATURES.
RESTRICT="network-sandbox test"

# Matches the go directive in go.mod.
BDEPEND=">=dev-lang/go-1.25.7"

src_compile() {
	local nuclei_ldflags=(
		"-s"
		"-w"
	)

	ego build \
		-trimpath \
		-buildmode=pie \
		-buildvcs=false \
		-ldflags "${nuclei_ldflags[*]}" \
		-o "${PN}" \
		./cmd/${PN}
}

src_install() {
	newbin "${PN}" "${PN}"

	dodoc README.md CONTRIBUTING.md

	# Install the man page when upstream ships one.
	if [[ -f man/man1/nuclei.1 ]]; then
		doman man/man1/nuclei.1
	fi
}

pkg_postinst() {
	elog "More information:"
	elog "  - Documentation: https://docs.projectdiscovery.io/tools/nuclei/"
	elog "  - Templates: https://github.com/projectdiscovery/nuclei-templates"
	elog ""
}