public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: David Seifert <soap@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Cc: David Seifert <soap@gentoo.org>
Subject: [gentoo-dev] [PATCH 1/2] optfeature.eclass: New eclass with definition from eutils
Date: Sun,  6 Sep 2020 17:47:30 +0200	[thread overview]
Message-ID: <20200906154731.162917-1-soap@gentoo.org> (raw)

Signed-off-by: David Seifert <soap@gentoo.org>
---
 eclass/optfeature.eclass | 63 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)
 create mode 100644 eclass/optfeature.eclass

diff --git a/eclass/optfeature.eclass b/eclass/optfeature.eclass
new file mode 100644
index 00000000000..b0082606cd6
--- /dev/null
+++ b/eclass/optfeature.eclass
@@ -0,0 +1,63 @@
+# Copyright 1999-2020 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: optfeature.eclass
+# @MAINTAINER:
+# base-system@gentoo.org
+# @BLURB: Advertise optional functionality that might be useful to users
+
+case "${EAPI:-0}" in
+	[0-7]) ;;
+	*)     die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}" ;;
+esac
+
+if [[ -z ${_OPTFEATURE_ECLASS} ]]; then
+_OPTFEATURE_ECLASS=1
+
+# @FUNCTION: optfeature
+# @USAGE: <short description> <package atom to match> [other atoms]
+# @DESCRIPTION:
+# Print out a message suggesting an optional package (or packages)
+# not currently installed which provides the described functionality.
+#
+# The following snippet would suggest app-misc/foo for optional foo support,
+# app-misc/bar or app-misc/baz[bar] for optional bar support
+# and either both app-misc/a and app-misc/b or app-misc/c for alphabet support.
+# @CODE
+#	optfeature "foo support" app-misc/foo
+#	optfeature "bar support" app-misc/bar app-misc/baz[bar]
+#	optfeature "alphabet support" "app-misc/a app-misc/b" app-misc/c
+# @CODE
+optfeature() {
+	debug-print-function ${FUNCNAME} "$@"
+
+	local i j msg
+	local desc=$1
+	local flag=0
+	shift
+	for i; do
+		for j in ${i}; do
+			if has_version "${j}"; then
+				flag=1
+			else
+				flag=0
+				break
+			fi
+		done
+		if [[ ${flag} -eq 1 ]]; then
+			break
+		fi
+	done
+	if [[ ${flag} -eq 0 ]]; then
+		for i; do
+			msg=" "
+			for j in ${i}; do
+				msg+=" ${j} and"
+			done
+			msg="${msg:0: -4} for ${desc}"
+			elog "${msg}"
+		done
+	fi
+}
+
+fi
-- 
2.28.0



             reply	other threads:[~2020-09-06 15:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-06 15:47 David Seifert [this message]
2020-09-06 15:47 ` [gentoo-dev] [PATCH 2/2] eutils.eclass: Use optfeature() from optfeature.eclass David Seifert
2020-09-06 19:49   ` Ulrich Mueller
2020-09-06 21:11     ` David Seifert
2020-09-07  7:37       ` Ulrich Mueller
2020-09-06 15:51 ` [gentoo-dev] [PATCH 1/2] optfeature.eclass: New eclass with definition from eutils Joonas Niilola
2020-09-06 18:12   ` David Seifert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200906154731.162917-1-soap@gentoo.org \
    --to=soap@gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox