# Copyright 2020-2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

CRATES="
	adler2@2.0.1
	aho-corasick@1.1.3
	anstream@0.6.21
	anstyle-parse@0.2.7
	anstyle-query@1.1.4
	anstyle-wincon@3.0.10
	anstyle@1.0.13
	anyhow@1.0.100
	app_dirs2@2.5.5
	arbitrary@1.4.2
	assert_cmd@2.0.17
	autocfg@1.5.0
	base64@0.22.1
	base64ct@1.8.0
	bitflags@2.9.4
	bstr@1.12.0
	bumpalo@3.19.0
	bytes@1.10.1
	cc@1.2.40
	cesu8@1.1.0
	cfg-if@1.0.3
	clap@4.5.48
	clap_builder@4.5.48
	clap_derive@4.5.47
	clap_lex@0.7.5
	colorchoice@1.0.4
	combine@4.6.7
	core-foundation-sys@0.8.7
	core-foundation@0.10.1
	core-foundation@0.9.4
	crc32fast@1.5.0
	der@0.7.10
	derive_arbitrary@1.4.2
	difflib@0.4.0
	doc-comment@0.3.3
	env_filter@0.1.3
	env_logger@0.11.8
	equivalent@1.0.2
	errno-dragonfly@0.1.2
	errno@0.2.8
	errno@0.3.14
	escargot@0.5.15
	fastrand@2.3.0
	filetime@0.2.26
	find-msvc-tools@0.1.3
	flate2@1.1.2
	float-cmp@0.10.0
	fnv@1.0.7
	foreign-types-shared@0.1.1
	foreign-types@0.3.2
	getrandom@0.2.16
	getrandom@0.3.3
	hashbrown@0.16.0
	heck@0.5.0
	http@1.3.1
	httparse@1.10.1
	indexmap@2.11.4
	is_terminal_polyfill@1.70.1
	itoa@1.0.15
	jiff-static@0.2.15
	jiff@0.2.15
	jni-sys@0.3.0
	jni@0.21.1
	libc@0.2.176
	libredox@0.1.10
	libz-rs-sys@0.5.2
	linux-raw-sys@0.11.0
	log@0.4.28
	memchr@2.7.6
	miniz_oxide@0.8.9
	native-tls@0.2.14
	ndk-context@0.1.1
	normalize-line-endings@0.3.0
	num-traits@0.2.19
	once_cell@1.21.3
	once_cell_polyfill@1.70.1
	openssl-macros@0.1.1
	openssl-probe@0.1.6
	openssl-sys@0.9.109
	openssl@0.10.73
	pager@0.16.1
	pem-rfc7468@0.7.0
	percent-encoding@2.3.2
	pkg-config@0.3.32
	portable-atomic-util@0.2.4
	portable-atomic@1.11.1
	predicates-core@1.0.9
	predicates-tree@1.0.12
	predicates@3.1.3
	proc-macro2@1.0.101
	quote@1.0.41
	r-efi@5.3.0
	redox_syscall@0.5.17
	regex-automata@0.4.11
	regex-syntax@0.8.6
	regex@1.11.3
	ring@0.17.14
	rustix@1.1.2
	rustls-native-certs@0.8.1
	rustls-pemfile@2.2.0
	rustls-pki-types@1.12.0
	rustls-platform-verifier-android@0.1.1
	rustls-platform-verifier@0.6.1
	rustls-webpki@0.103.7
	rustls@0.23.32
	ryu@1.0.20
	same-file@1.0.6
	schannel@0.1.28
	security-framework-sys@2.15.0
	security-framework@2.11.1
	security-framework@3.5.1
	serde@1.0.228
	serde_core@1.0.228
	serde_derive@1.0.228
	serde_json@1.0.145
	serde_spanned@0.6.9
	shlex@1.3.0
	simd-adler32@0.3.7
	subtle@2.6.1
	syn@2.0.106
	tempfile@3.23.0
	terminal_size@0.4.3
	termtree@0.5.1
	thiserror-impl@1.0.69
	thiserror@1.0.69
	toml@0.8.23
	toml_datetime@0.6.11
	toml_edit@0.22.27
	toml_write@0.1.2
	unicode-ident@1.0.19
	untrusted@0.9.0
	ureq-proto@0.5.2
	ureq@3.1.2
	utf-8@0.7.6
	utf8parse@0.2.2
	vcpkg@0.2.15
	wait-timeout@0.2.1
	walkdir@2.5.0
	wasi@0.11.1+wasi-snapshot-preview1
	wasi@0.14.7+wasi-0.2.4
	wasip2@1.0.1+wasi-0.2.4
	webpki-root-certs@1.0.2
	webpki-roots@1.0.2
	winapi-i686-pc-windows-gnu@0.4.0
	winapi-util@0.1.11
	winapi-x86_64-pc-windows-gnu@0.4.0
	winapi@0.3.9
	windows-link@0.2.0
	windows-sys@0.45.0
	windows-sys@0.52.0
	windows-sys@0.59.0
	windows-sys@0.60.2
	windows-sys@0.61.1
	windows-targets@0.42.2
	windows-targets@0.52.6
	windows-targets@0.53.4
	windows_aarch64_gnullvm@0.42.2
	windows_aarch64_gnullvm@0.52.6
	windows_aarch64_gnullvm@0.53.0
	windows_aarch64_msvc@0.42.2
	windows_aarch64_msvc@0.52.6
	windows_aarch64_msvc@0.53.0
	windows_i686_gnu@0.42.2
	windows_i686_gnu@0.52.6
	windows_i686_gnu@0.53.0
	windows_i686_gnullvm@0.52.6
	windows_i686_gnullvm@0.53.0
	windows_i686_msvc@0.42.2
	windows_i686_msvc@0.52.6
	windows_i686_msvc@0.53.0
	windows_x86_64_gnu@0.42.2
	windows_x86_64_gnu@0.52.6
	windows_x86_64_gnu@0.53.0
	windows_x86_64_gnullvm@0.42.2
	windows_x86_64_gnullvm@0.52.6
	windows_x86_64_gnullvm@0.53.0
	windows_x86_64_msvc@0.42.2
	windows_x86_64_msvc@0.52.6
	windows_x86_64_msvc@0.53.0
	winnow@0.7.13
	wit-bindgen@0.46.0
	xdg@2.5.2
	yansi@1.0.1
	zeroize@1.8.2
	zip@5.1.1
	zlib-rs@0.5.2
	zopfli@0.8.2
"

inherit cargo flag-o-matic shell-completion

DESCRIPTION="A very fast implementation of tldr in Rust."
HOMEPAGE="https://github.com/tldr-pages/tldr
	https://github.com/dbrgn/tealdeer"

if [[ "${PV}" == *9999* ]]; then
	inherit git-r3
	EGIT_REPO_URI="https://github.com/tealdeer-rs/tealdeer.git"
	src_unpack() {
		git-r3_src_unpack
		cargo_live_src_unpack
	}
else
	SRC_URI="https://github.com/dbrgn/${PN}/archive/v${PV}.tar.gz -> ${P}.tar.gz"
	SRC_URI+=" ${CARGO_CRATE_URIS}"
	KEYWORDS="~amd64"
fi

LICENSE="Apache-2.0 ISC MIT MPL-2.0"
# Dependent crate licenses
LICENSE+=" Apache-2.0 BSD CDLA-Permissive-2.0 ISC MIT Unicode-3.0 ZLIB"
SLOT="0"

RDEPEND="!app-text/tldr"

QA_FLAGS_IGNORED="usr/bin/tldr"

# Tests require network connection
RESTRICT="test"
PROPERTIES="test_network"

src_configure() {
	filter-flags '-flto*' # ring crate fails compile with lto
	cargo_src_configure
}

src_install() {
	cargo_src_install
	einstalldocs

	newbashcomp completion/bash_tealdeer tldr

	newzshcomp completion/zsh_tealdeer _tldr

	newfishcomp completion/fish_tealdeer tldr.fish
}