Gentoo Archives: gentoo-dev

From: Mike Frysinger <vapier@g.o>
To: gentoo-dev@l.g.o
Cc: David Leverton <levertond@××××××××××.com>
Subject: Re: [gentoo-dev] versionator.eclass: convert to eshopts_{push,pop}
Date: Mon, 19 Jul 2010 20:34:02
Message-Id: 201007191630.43932.vapier@gentoo.org
In Reply to: Re: [gentoo-dev] versionator.eclass: convert to eshopts_{push,pop} by David Leverton
On Monday, July 19, 2010 16:07:56 David Leverton wrote:
> On 19 July 2010 20:43, Mike Frysinger <vapier@g.o> wrote: > > On Monday, July 19, 2010 03:38:39 Ciaran McCreesh wrote: > >> On Sun, 18 Jul 2010 20:17:45 -0700 Alec Warner wrote: > >> > Can we do away with all the extra foo && return bullshit and just set > >> > a trap? > >> > > >> > trap "eshopts pop" RETURN > >> > > >> > ? > >> > >> That strikes me as a horribly fragile way of doing things that's bound > >> to come back and screw things up at some point... > > > > nifty in theory, but i'm inclined to agree with Ciaran > > Is something like the below function too hideous (not massively > tested, but it seems to work)? Usage is something like: > > [dleverton@shiny-one ~] $ foo() { shopt -p extglob; } > [dleverton@shiny-one ~] $ eshopts_need foo -s extglob
i imagine this might be useful in some scenarios, but i think the more common usage is to enable things inline. otherwise, the exported API would need to be wrapped internally like: get_all_version_components() { eshopts_need _get_all_version_components -s extglob } and at this point, it's hard to say this is better than just doing: get_all_version_components() { eshopts_push -s extglob _get_all_version_components eshopts_pop } ... or the existing code we have now. although, the method we have now also allows for disabling of shopts before calling `die`. not sure if that's important, but i think it's better to disable before all exit/termination points. so unless their is a consumer now we can point to in the tree, i'm inclined to leave this alone.
> eshopts_need() { > [[ $# -ge 1 ]] || die "eshopts_need needs at least one argument" > local func=$1 > shift > local opts=( "${@}" ) > if [[ $1 == -[su] ]] ; then > eval "_eshopts_need_shopt_$(declare -f $func)" > eval "$func() { > local old=\$(shopt -p) > $(declare -p opts) > shopt \"\${opts[@]}\" > _eshopts_need_shopt_$func \"\$@\" > local status=\$? > eval \"\$old\" > return \$status > }"
there are already eshopts_push/pop funcs that accomodate more things than the usage here, but i imagine you did it this way just to make testing in your shell easier -mike

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies

Subject Author
Re: [gentoo-dev] versionator.eclass: convert to eshopts_{push,pop} David Leverton <levertond@××××××××××.com>