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 6696E1581F3 for ; Tue, 26 Nov 2024 06:53:15 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 34B8EE07F1; Tue, 26 Nov 2024 06:53:10 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 9A16FE07EA for ; Tue, 26 Nov 2024 06:53:08 +0000 (UTC) From: =?utf-8?Q?Ulrich_M=C3=BCller?= To: gentoo-dev@lists.gentoo.org Subject: Re: [gentoo-dev] New eclass v2: eapi9-pipestatus.eclass In-Reply-To: ("Ulrich =?utf-8?Q?M=C3=BCller=22's?= message of "Sun, 24 Nov 2024 13:24:43 +0100") References: Date: Tue, 26 Nov 2024 07:52:49 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) 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 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-Archives-Salt: fbf3ee92-5b01-4e28-ae9e-f0047154b8c1 X-Archives-Hash: d4a0c704b71fed401f560e555165388b --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable >>>>> On Sun, 24 Nov 2024, Ulrich M=C3=BCller wrote: > This implements a pipestatus command, as discussed in bug 566342 [1] > and on IRC. > =E2=95=93=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > =E2=95=91 Tests the shell's pipe status array, i.e. the exit status of the > =E2=95=91 command(s) in the most recently executed foreground pipeline. > =E2=95=91 Returns shell true (0) if all elements are zero, or the last > =E2=95=91 non-zero element otherwise. If called with -v as the first argu= ment, > =E2=95=91 also outputs the pipe status array as a space-separated list. > =E2=95=99=E2=94=80=E2=94=80=E2=94=80=E2=94=80 Updated version: =2D No functional changes =2D Minor style changes =2D Added a comment Thanks again for the feedback. --=-=-= Content-Type: text/plain; charset=utf-8 Content-Disposition: inline; filename=eapi9-pipestatus.eclass Content-Transfer-Encoding: quoted-printable # Copyright 2024 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 # @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}" # @CODE # # Caveat: "pipestatus" must be the next command following the pipeline. # In particular, the "local" declaration must be before the pipeline, # otherwise it would reset the status. case ${EAPI} in 7|8) ;; *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;; esac # @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 status=3D( "${PIPESTATUS[@]}" ) local s ret=3D0 verbose=3D"" [[ ${1} =3D=3D -v ]] && { verbose=3D1; shift; } [[ $# -ne 0 ]] && die "usage: ${FUNCNAME} [-v]" for s in "${status[@]}"; do [[ ${s} -ne 0 ]] && ret=3D${s} done [[ ${verbose} ]] && echo "${status[@]}" return "${ret}" } --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQFDBAEBCAAtFiEEtDnZ1O9xIP68rzDbUYgzUIhBXi4FAmdFcEEPHHVsbUBnZW50 b28ub3JnAAoJEFGIM1CIQV4ul4EH/iU5hlDATQPkRoVlSQWkwlygD6bRYSdsSoQz 7AxmFmEJCP+BzktUPPXXm9vSeEQXcfGFc6Df67I3q3Dvn9S5C0nlmrW+qF+zJ8Sr J/G2tU5zMTcWHbFNLFwbDf0LQDhI1BVMOcfIxf7Nb3AXDcvoVrEKqCZs2IUDnSqS PRmd+Tzpvfx+BB1WdgNosaGJ5C7UxV3xbP1Hth3HvY2s9aSIh6nEdFC6CVsp54CF 0YZ8iAxmPxCKi9p4oZ558CSPfeBVHk174eZQCqC0fzd0QAMJLOSJrWccOFChpeMn PZapk9hn1UecrqUNvhc0PbIyY2OrStmJC5YYT8tOfDg+8+oAzr8= =c2ov -----END PGP SIGNATURE----- --==-=-=--