[TRIGGER] cast_section_installed (Feature #192)
Description
use of a "cast_section_installed" with section name as argument
This would be used by
perl (cast_section_installed perl-cpan)
python (cast_section_installed python-pypi)
Usable by shell or scripting languages to mass-re-casting of everything from a dependency base
History
Updated by Bor Kraljič almost 2 years ago
That is pretty simple. But I decided that function that would only return installed spells would be even more useful:
#---
## Get list of spells installed in section
## @param $1 - section name
## @param $2 - (optional) variable to set
##
## @Stdout - list of spells if $2 is not set
#---
function get_installed_spells_in_section() {
local section=$1
codex_find_section_by_name $section section_path
for spell in $(codex_get_spell_names $section_path); do
if spell_installed $spell; then
local instaled_spells="$instaled_spells $spell"
fi
done
if [[ -z $2 ]]; then
echo "$instaled_spells"
else
eval "$2=\"\$instaled_spells\""
fi
}
(sorcery functions are used in this function. But I think we source sorcery in FUNCTIONS so that isn't a problem at all)
With that you can do what you wanted pretty simple:
for spell in $(get_installed_spells_in_section some_section); do cast $spell done
With get_installed_spells_in_section function we can do lots of simple functions that could be useful. For example you suggested cast_installed_spells_in_section (or we use one shorter name)...
Such function would look something like this:
function cast_installed_spells_in_section() {
for spell in $(get_installed_spells_in_section $1); do
cast $spell
done
}
However not sure if FUNCTIONS are available in TRIGGERS...
Updated by Bor Kraljič almost 2 years ago
About my last comment. functions from file FUNCTIONS are available in TRIGGERS however not in UP_TRIGGERS.