aboutsummaryrefslogtreecommitdiff
path: root/libs/tool
diff options
context:
space:
mode:
Diffstat (limited to 'libs/tool')
-rwxr-xr-xlibs/tool69
1 files changed, 44 insertions, 25 deletions
diff --git a/libs/tool b/libs/tool
index 3a9c4a1b..8ed70e18 100755
--- a/libs/tool
+++ b/libs/tool
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
# Copyright (C) 2016 Paul Kocialkowski <contact@paulk.fr>
#
@@ -15,16 +15,16 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-TOOL_ACTIONS_GENERIC="usage update execute"
-TOOL_ACTIONS_HELPERS="arguments"
-TOOL_FUNCTIONS=$( for action in $TOOL_ACTIONS_GENERIC ; do echo "$action" "$action""_check" ; done ; echo "$TOOL_ACTIONS_HELPERS" )
+TOOL_ACTIONS_GENERIC=(usage update execute)
+TOOL_ACTIONS_GENERIC_IGNORE_CHECK=(usage update)
+TOOL_ACTIONS_HELPERS=(arguments)
tool_include() {
local tool=$1
local tool_path=$( tool_path "$tool" )
- unset -f $TOOL_FUNCTIONS
+ unset -f "${TOOL_ACTIONS[@]}"
. "$tool_path/$tool"
@@ -46,9 +46,9 @@ tool_helper_include() {
tool_check() {
local tool="${1##*/}"
- local tool_path="$(tool_path "${tool}")"
+ local tool_path="$(tool_path "$tool")"
- if ! [[ -f "${tool_path}/${tool}" ]]; then
+ if ! [[ -f "$tool_path/$tool" ]]; then
return 1
fi
}
@@ -79,7 +79,7 @@ tool_action() {
if ! tool_check "$tool"
then
- printf "Tool $tool check failed\n" >&2
+ printf '%s\n' "Tool $tool check failed" >&2
return 1
fi
@@ -97,7 +97,7 @@ tool_action() {
return 0
fi
- printf "Tool $tool $action (with ${arguments:-no argument})\n" >&2
+ printf '%s\n' "Tool $tool $action (with ${arguments:-no argument})" >&2
(
set -e
@@ -106,10 +106,10 @@ tool_action() {
if [ $? -ne 0 ]
then
- printf "\nTool $tool $action (with ${arguments:-no argument}) failed\n" >&2
+ printf '\n%s\n' "Tool $tool $action (with ${arguments:-no argument}) failed" >&2
return 1
else
- printf "\nTool $tool $action (with ${arguments:-no argument}) completed\n" >&2
+ printf '\n%s\n' "Tool $tool $action (with ${arguments:-no argument}) completed" >&2
fi
)
}
@@ -125,7 +125,7 @@ tool_action_check() {
if ! tool_check "$tool"
then
- printf "Tool $tool check failed\n" >&2
+ printf '%s\n' "Tool $tool check failed" >&2
return 1
fi
@@ -162,7 +162,7 @@ tool_action_helper() {
if ! tool_check "$tool"
then
- printf "Tool $tool check failed\n" >&2
+ printf '%s\n' "Tool $tool check failed" >&2
return 1
fi
@@ -193,19 +193,38 @@ tool_action_arguments_recursive() {
then
tool_action "$action" "$tool" "$@"
else
- echo "$action_helper_arguments" | while read argument
+ printf '%s\n' "$action_helper_arguments" | while read argument
do
tool_action_arguments_recursive "$action" "$tool" "$@" "$argument"
done
fi
}
+tool_arguments_targets() {
+ local tool="$1"
+ shift
+
+ local tool_path="$(tool_path "$tool")"
+ local targets_path="$tool_path/$CONFIGS"
+ local argument
+
+ for argument in "$@"; do
+ targets_path="$targets_path/$argument"
+ done
+
+ targets_path="$targets_path/$TARGETS"
+
+ if [[ -f "$targets_path" ]]; then
+ cat "$targets_path"
+ fi
+}
+
tool_path() {
local tool=$1
local tool_path="$root/$TOOLS/$tool"
- echo "$tool_path"
+ printf '%s\n' "$tool_path"
}
tool_sources_path() {
@@ -224,7 +243,7 @@ tool_sources_path() {
if directory_filled_check "$path"
then
- echo "$path"
+ printf '%s\n' "$path"
return
fi
done
@@ -234,23 +253,23 @@ tool_usage_actions() {
local tool=$1
shift
- printf "\nGeneric actions:\n"
+ printf '\n%s\n' 'Generic actions:'
- for action in $TOOL_ACTIONS_GENERIC
+ for action in "${TOOL_ACTIONS_GENERIC[@]}"
do
if function_check "$action"
then
- printf " $action\n"
+ printf '%s\n' " $action"
fi
done
if [ $# -gt 0 ]
then
- printf "\nSpecific actions:\n"
+ printf '\n%s\n' 'Specific actions:'
for action in "$@"
do
- printf " $action\n"
+ printf '%s\n' " $action"
done
fi
}
@@ -259,7 +278,7 @@ tool_usage_arguments() {
local tool=$1
shift
- printf "\nArguments:\n"
+ printf '\n%s\n' 'Arguments:'
tool_usage_arguments_recursive "$tool" " " "$@"
}
@@ -275,9 +294,9 @@ tool_usage_arguments_recursive() {
if ! [ -z "$action_helper_arguments" ]
then
- echo "$action_helper_arguments" | while read argument
+ printf '%s\n' "$action_helper_arguments" | while read argument
do
- printf "$spacing$argument\n"
+ printf '%s\n' "$spacing$argument"
tool_usage_arguments_recursive "$tool" " $spacing" "$@" "$argument"
done
fi
@@ -316,7 +335,7 @@ tool_file_path() {
return 1
fi
- echo "$file_path"
+ printf '%s\n' "$file_path"
}
tool_file_test() {