From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Subject: Re: [gentoo-dev] New eclass: eapi9-pipestatus.eclass
Date: Sun, 24 Nov 2024 13:58:04 +0100 [thread overview]
Message-ID: <5e0e2dd372bf3a60a9c2dfb8b68bf7b18b7c2b99.camel@gentoo.org> (raw)
In-Reply-To: <u4j3wrf90@urania.mail-host-address-is-not-set>
[-- Attachment #1: Type: text/plain, Size: 2227 bytes --]
On Sun, 2024-11-24 at 13:24 +0100, Ulrich Müller wrote:
> # Copyright 2024 Gentoo Authors
> # Distributed under the terms of the GNU General Public License v2
>
> # @ECLASS: eapi9-pipestatus.eclass
> # @MAINTAINER:
> # Ulrich Müller <ulm@gentoo.org>
> # @AUTHOR:
> # Ulrich Müller <ulm@gentoo.org>
> # @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=$(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
>
> 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 -a status=( "${PIPESTATUS[@]}" )
> local s ret=0
>
> [[ $# -gt 0 && ${1} != -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 '&&'.
>
> [[ ${1} == -v ]] && echo "${status[@]}"
>
> for s in "${status[@]}"; do
> [[ ${s} -ne 0 ]] && ret=${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
>
> return "${ret}"
> }
--
Best regards,
Michał Górny
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 512 bytes --]
next prev parent reply other threads:[~2024-11-24 12:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-24 12:24 [gentoo-dev] New eclass: eapi9-pipestatus.eclass Ulrich Müller
2024-11-24 12:58 ` Michał Górny [this message]
2024-11-24 14:12 ` Ulrich Müller
2024-11-26 6:52 ` [gentoo-dev] New eclass v2: eapi9-pipestatus.eclass Ulrich Müller
2024-11-27 10:41 ` [gentoo-dev] New eclass: eapi9-pipestatus.eclass Florian Schmaus
2024-11-27 11:52 ` Michał Górny
2024-11-27 12:32 ` Ulrich Müller
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=5e0e2dd372bf3a60a9c2dfb8b68bf7b18b7c2b99.camel@gentoo.org \
--to=mgorny@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