Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bugzilla DB migration completed. Please report issues to Infra team via email via infra@gentoo.org or IRC
Bug 382963 - usex: new `use` type helper
Summary: usex: new `use` type helper
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Hosted Projects
Classification: Unclassified
Component: PMS/EAPI (show other bugs)
Hardware: All Linux
: Normal enhancement (vote)
Assignee: PMS/EAPI
URL:
Whiteboard: in-eapi-5
Keywords:
Depends on:
Blocks: future-eapi
  Show dependency tree
 
Reported: 2011-09-14 15:02 UTC by SpanKY
Modified: 2012-09-23 06:44 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description SpanKY gentoo-dev 2011-09-14 15:02:40 UTC
let's add a new helper named "usex".  example implementation:
usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; }

spec being:
usex <USE flag> [true output] [false output] [true suffix] [false suffix]

if any output options are omitted (an empty string does not count as omission, hence "${var-foo}" and not "${var:-foo}", they'll default to the USE flag

the suffix options get appended to the related output if they're specified

while the output/suffix options could be merged so that usex only takes 3 arguments, it limits the caller a little bit.  the extended args allow for tricks like:
    usex foo --with{,out}-option =fast
where as a combined arg approach would force callers to be more verbose:
    usex foo --with-option=fast --without-option

and for the people who prefer to be more verbose, the latter form works even when usex accepts 5 args instead of 3
Comment 1 Ulrich Müller gentoo-dev 2011-09-14 15:45:32 UTC
> the extended args allow for tricks like:
>     usex foo --with{,out}-option =fast

Can you imagine a frequent usage case where the suffix isn't prefixed by an = sign? If not, the following would make the behaviour more consistent with what we have in use_with() and use_enable():

  usex() { use "$1" && echo "${2-yes}${4+=$4}" || echo "${3-no}${5+=$5}" ; }

Your above example would become:
  usex foo --with{,out}-option fast
Comment 2 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2011-09-14 16:16:12 UTC
(In reply to comment #1)
> > the extended args allow for tricks like:
> >     usex foo --with{,out}-option =fast
> 
> Can you imagine a frequent usage case where the suffix isn't prefixed by an =
> sign? If not, the following would make the behaviour more consistent with what
> we have in use_with() and use_enable():
> 
>   usex() { use "$1" && echo "${2-yes}${4+=$4}" || echo "${3-no}${5+=$5}" ; }
> 
> Your above example would become:
>   usex foo --with{,out}-option fast

Why not just 'usex foo --with{,out}-option=fast' with = adding handled explicitly by caller?
Comment 3 SpanKY gentoo-dev 2011-09-14 17:03:49 UTC
i'd rather not encode syntax decisions into the helper.  i assume i cant foresee all the possibilities.  and the overhead on the caller is minuscule.
Comment 4 Ulrich Müller gentoo-dev 2012-08-31 13:48:41 UTC
> usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; }

This returns always true. Is this what we want?
Maybe it would be more natural to return the status of the "use" call.
Comment 5 Ulrich Müller gentoo-dev 2012-08-31 14:19:05 UTC
(In reply to comment #4)
> > usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; }
> 
> This returns always true. Is this what we want?

Hm, use_with and use_enable do the same. So I guess this is o.k.