public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: Chris Reffett <creffett@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Subject: [gentoo-dev] [PATCH] eutils.eclass: add optfeature() function
Date: Thu, 23 Jan 2014 11:24:41 -0500	[thread overview]
Message-ID: <52E14249.8000502@gentoo.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 856 bytes --]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello all,
After some discussion on good ways to communicate optional
dependencies to users, I was shown the optfeature() function in
net-misc/netctl. Gentoo contributor Andrew Hamilton and I came up with
a cleaned up and expanded version of it, and I would like to add it to
eutils.eclass to provide a standard way of notifying users of optional
dependencies. The patch to eutils.eclass is attached.

Chris Reffett
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iKYEARECAGYFAlLhQklfFIAAAAAALgAoaXNzdWVyLWZwckBub3RhdGlvbnMub3Bl
bnBncC5maWZ0aGhvcnNlbWFuLm5ldEM2NzU5RjUyMDczREJDQkVDQTBDRkE1NERC
Nzk1QThBNDI2MTgzNTQACgkQ23laikJhg1TDkwCeJ7MQliIiI6ViSkZzD+eIYM/J
0F4AoIVMP32HenJcjOkTIJkd6vGniiSi
=+oIe
-----END PGP SIGNATURE-----

[-- Attachment #2: eutils_add_optfeature_v6.patch --]
[-- Type: text/x-patch, Size: 1340 bytes --]

--- eutils.eclass	2014-01-22 23:36:35.819000000 -0500
+++ eutils.eclass.patched	2014-01-23 00:37:07.907000000 -0500
@@ -1729,4 +1729,49 @@
 
 check_license() { die "you no longer need this as portage supports ACCEPT_LICENSE itself"; }
 
+# @FUNCTION: optfeature
+# @USAGE: <short description> <package atom to match> [other atoms]
+# @DESCRIPTION:
+# Print out a message suggesting an optional package (or packages) which
+# provide 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
+#
+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="${msg} ${j} and"
+			done
+			msg="${msg:0: -4} for ${desc}"
+			elog "${msg}"
+		done
+	fi
+}
+
 fi

             reply	other threads:[~2014-01-23 16:25 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-23 16:24 Chris Reffett [this message]
2014-01-23 16:28 ` [gentoo-dev] [PATCH] eutils.eclass: add optfeature() function Michał Górny
2014-01-23 16:36   ` Chris Reffett
2014-01-23 16:48     ` Michał Górny
2014-01-25 10:12       ` Markos Chandras
2014-01-25 10:35         ` Michał Górny
2014-01-25 13:09         ` Chris Reffett
2014-01-25 13:27           ` Markos Chandras

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=52E14249.8000502@gentoo.org \
    --to=creffett@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