From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 5811E1581FB for ; Sun, 24 Nov 2024 12:58:14 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id B2745E07F0; Sun, 24 Nov 2024 12:58:09 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 672BBE07EA for ; Sun, 24 Nov 2024 12:58:09 +0000 (UTC) Message-ID: <5e0e2dd372bf3a60a9c2dfb8b68bf7b18b7c2b99.camel@gentoo.org> Subject: Re: [gentoo-dev] New eclass: eapi9-pipestatus.eclass From: =?UTF-8?Q?Micha=C5=82_G=C3=B3rny?= To: gentoo-dev@lists.gentoo.org Date: Sun, 24 Nov 2024 13:58:04 +0100 In-Reply-To: References: Organization: Gentoo Content-Type: multipart/signed; micalg="pgp-sha512"; protocol="application/pgp-signature"; boundary="=-cR382cGfM8mUO+iglNkH" User-Agent: Evolution 3.52.4 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 X-Archives-Salt: 7e5a1398-11de-4342-a49f-dbe92745f5d1 X-Archives-Hash: 157c8498c2ab383eb0cd62bd2b4279f6 --=-cR382cGfM8mUO+iglNkH Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, 2024-11-24 at 13:24 +0100, Ulrich M=C3=BCller wrote: > # Copyright 2024 Gentoo Authors > # Distributed under the terms of the GNU General Public License v2 >=20 > # @ECLASS: eapi9-pipestatus.eclass > # @MAINTAINER: > # Ulrich M=C3=BCller > # @AUTHOR: > # Ulrich M=C3=BCller > # @SUPPORTED_EAPIS: 7 8 > # @BLURB: test the PIPESTATUS array > # @DESCRIPTION: > # A stand-alone implementation of a possible future pipestatus command > # (which would be aimed for EAPI 9). It is meant as a replacement for > # "assert". In its simplest form it can be called like this: > # > # @CODE > # foo | bar > # pipestatus || die > # @CODE > # > # With the -v option, the command will also echo the pipe status array, > # so it can be assigned to a variable like in the following example: > # > # @CODE > # local status > # foo | bar > # status=3D$(pipestatus -v) || die "foo | bar failed, status ${status}" I suppose you may want to put a verbose warning not to put "local" on the same line, because people are going to do that as an "obvious" optimization. > # @CODE >=20 > case ${EAPI} in > 7|8) ;; > *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;; > esac >=20 > # @FUNCTION: pipestatus > # @USAGE: [-v] > # @RETURN: last non-zero element of PIPESTATUS, or zero if all are zero > # @DESCRIPTION: > # Test the PIPESTATUS array, i.e. the exit status of the command(s) > # in the most recently executed foreground pipeline. If called with > # option -v, also output the PIPESTATUS array. > pipestatus() { > local -a status=3D( "${PIPESTATUS[@]}" ) > local s ret=3D0 >=20 > [[ $# -gt 0 && ${1} !=3D -v || $# -gt 1 ]] \ Please use parentheses when you combine && and ||, if only for the sake of readability. > && die "${FUNCNAME}: bad arguments: $@" Replace the '\' with the '&&'. >=20 > [[ ${1} =3D=3D -v ]] && echo "${status[@]}" >=20 > for s in "${status[@]}"; do > [[ ${s} -ne 0 ]] && ret=3D${s} I suppose it's just my C-foo talking and completely needless optimization here, but it really itches me to iterate the array backwards and return on the first match. > done >=20 > return "${ret}" > } --=20 Best regards, Micha=C5=82 G=C3=B3rny --=-cR382cGfM8mUO+iglNkH Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- iQFGBAABCgAwFiEEx2qEUJQJjSjMiybFY5ra4jKeJA4FAmdDItwSHG1nb3JueUBn ZW50b28ub3JnAAoJEGOa2uIyniQOqekH/0/0UlpZQq68rD9wjU7n1LjAdE+UXwcw S4kkSHJ0xayowgxjp0KYl45bL5/Y+xoc8qeSd5MN4Frf1XS3tZcPRA9lW7YmgHjw 52V0p16hkWVbj+tby7YYjg2U+gtIUb14dLl+EDmr9pHQemmYX+0crGC4TTRGarQA uqiSMPi77xGE5ILfG00kK6sQLCjPySipdyvT51vpFJLpBePUxVI3MlXPWa0LhM52 90N4u9muNkovltliiekLfBUySh8+WoQXaUIZ2YWs3+OCDChUGS3UtmsaRLTbWgnE 6VPg3pL9yg5ieCK4n9sT2H6LVWUs0mnmRDFQaxUY2kYFw5eHTMbWsSY= =Y71a -----END PGP SIGNATURE----- --=-cR382cGfM8mUO+iglNkH--