Skip to Content.
Sympa Menu

sm-discuss - Re: [SM-Discuss] Spell branches

sm-discuss AT lists.ibiblio.org

Subject: Public SourceMage Discussion List

List archive

Chronological Thread  
  • From: Bor Kraljič <pyrobor AT ver.si>
  • To: "sm-discuss @ lists. ibiblio. org" <sm-discuss AT lists.ibiblio.org>
  • Subject: Re: [SM-Discuss] Spell branches
  • Date: Tue, 13 Sep 2011 09:40:34 +0200

On 13. of Sep 2011 8:26:09 flux <flux AT sourcemage.org> wrote:
> Ismael Luceno (ismael.luceno AT gmail.com) wrote [11.09.12 11:26]:
> > Some spells support multiple branches. I would like to remove the
> > duplication to certain extent, by adding a new function that would
> > take a list of branches, query which one the user wants and if it
> > should be updated automatically (if applicable).
> >
> > Something like:
> > function select_branch() {
> >
> > local spell="$1" tmp &&
> > shift &&
> >
> > if [[ $# > 1 ]]; then
> >
> > config_query_list "$spell"_BRANCH \
> >
> > "Select one of the available branches:" "$@" &&
> >
> > eval tmp=\$"$spell"_BRANCH
> >
> > else
> >
> > eval "$spell"_BRANCH=\""$1"\" &&
> > tmp="$1"
> >
> > fi &&
> >
> > if [[ "${tmp/-*}" = scm ]]; then
> >
> > config_query "$spell"_SCM_AUTOUPDATE \
> >
> > 'Update on every system update?' n
> >
> > fi
> >
> > }
> >
> > Opinions?
>
> A slightly improved version of the code is as follows:
>
> function select_branch() {
> local spell="$1" tmp &&
> shift &&
>
> if [[ "$#" > 1 ]]; then
> config_query_list "$spell"_BRANCH \
> "Select one of the available branches:" "$@"
> else
> eval "$spell"_BRANCH=\""$spell"\"
> fi &&
>
> eval tmp=\"\$"$spell"_BRANCH\" &&
>
> if [[ "$tmp" != "$spell" && "${tmp/-*}" = "scm" ]]; then
> config_query "$spell"_SCM_AUTOUPDATE \
I think most of var should be uppercase. For that you can use function I just
pushed into FUNCTIONS:
local uppercase_spell=$(get_up_spell_name $spell)
And then use it with
"$uppercase_spell"_SCM_AUTOUPDATE
and other such occasions.

Regards, Bor

> 'Update on every system update?' n
> fi
> }
>
> This is more "correct" in that a spell named scm-foo wouldn't
> erroneously trigger the second if block to succeed. It's also a bit more
> readable in how tmp gets set (and uses the "$spell" variable instead of
> $1, so the value is more readable as well).




Archive powered by MHonArc 2.6.24.

Top of Page