#!/bin/bash
# tool - Tool Script Support
set -e
######
# Tool Names
# is_tool() - Returns success if the given string ($1) is a tool name ($1).
# $1 - Name of tool
is_tool() { in_list $1 "${package_apps[@]}"; }
# tool_category() - Prints the category for the given tool ($1).
# If the tool exists does not exist in any category, prints nothing.
# $1 - Name of tool
tool_category() { [ "${1/\//}" = "$1" ] || echo "${1%/*}"; }
# tool_cats() - Prints the categories for the tiven tools ($@). If no
# tools are given, prints all tool categories.
tool_cats() {
local -a cats=( "$@" )
[ "${cats[*]}" ] || cats=( "${package_apps[@]}" )
list_map tool_category cats
list_filter_empty cats
list_unique cats
qsort_list cats
local IFS=$'\n'
echo "${cats[*]}"
}
# tool_name() - Prints the base name of the given tool ($1)
# $1 - Name of tool
tool_name() { echo "${1##*/}"; }
# tool_names() - Prints the base names of the given tools ($@). If no
# tools are given, prints all tool names.
tool_names() {
local -a names=( "$@" )
[ "${names[*]}" ] || names=( "${package_apps[@]}" )
list_map tool_name names
qsort_list cats
local IFS=$'\n'
echo "${names[*]}"
}
######
# Tool Symbols
# tool_symbol() - Prints the symbol name for the given tool ($1).
# $1 - Name of tool
tool_symbol() { echo "tool_$1"; }
######
# Tool Execution
# for_each_tool() - Run the given command ($@) for all package tools.
for_each_tool() { run_for_each "$*" $(tool_names); }
# run_each_tool() - Run the given command ($@) for all package tools.
run_each_tool() {
local -a tool_args=( "$@" )
for_each _run_each_tool $(tool_names)
}
_run_each_tool() { run $1 "${tool_args[@]}"; }
# run_tool_version() - Runs the version command for the given tool ($1).
# $1 - Name of tool
run_tool_version() { quiet=true run $1 --version; }
######
# Tool Dependencies
# tool_class_deps() - Returns a list of all native package dependencies
# for the given tool class ($1).
# $1 - Name of class: `client` or `server`
tool_class_deps() {
local class=$1
run_each_tool app $class deps | xargs -n 1 echo | sort -u
}
Generated on Fri Jul 28 14:35:06 PDT 2017 by mcsh d14 v0.23.0.