aboutsummaryrefslogtreecommitdiff
path: root/libs/tool
diff options
context:
space:
mode:
Diffstat (limited to 'libs/tool')
-rwxr-xr-xlibs/tool83
1 files changed, 51 insertions, 32 deletions
diff --git a/libs/tool b/libs/tool
index 03d2d508..2732238a 100755
--- a/libs/tool
+++ b/libs/tool
@@ -22,11 +22,11 @@ TOOL_ACTIONS_HELPERS=(arguments)
tool_include() {
local tool=$1
- local tool_path=$( tool_path "$tool" )
+ local tool_path=$(tool_path "$tool")
unset -f "${TOOL_ACTIONS[@]}"
- . "$tool_path/$tool"
+ source "$tool_path/$tool"
tool_helper_include "$tool"
}
@@ -34,21 +34,21 @@ tool_include() {
tool_helper_include() {
local tool=$1
- local tool_path=$( tool_path "$tool" )
+ local tool_path=$(tool_path "$tool")
local include="$tool_path/$tool-helper"
- if [ -f "$include" ]
+ if [[ -f "$include" ]]
then
- . "$include"
+ source "$include"
fi
}
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,13 +79,13 @@ tool_action() {
if ! tool_check "$tool"
then
- printf '%s\n' "Tool $tool check failed" >&2
+ printf 1>&2 '%s\n' "Tool $tool check failed"
return 1
fi
tool_action_check "$action" "$tool" "$@"
- if [ $? -eq 0 ]
+ if [[ $? -eq 0 ]]
then
return 0
fi
@@ -97,19 +97,19 @@ tool_action() {
return 0
fi
- printf '%s\n' "Tool $tool $action (with ${arguments:-no argument})" >&2
+ printf 1>&2 '%s\n' "Tool $tool $action (with ${arguments:-no argument})"
(
set -e
"$action" "$@"
)
- if [ $? -ne 0 ]
+ if [[ $? -ne 0 ]]
then
- printf '\n%s\n' "Tool $tool $action (with ${arguments:-no argument}) failed" >&2
+ printf 1>&2 '\n%s\n' "Tool $tool $action (with ${arguments:-no argument}) failed"
return 1
else
- printf '\n%s\n' "Tool $tool $action (with ${arguments:-no argument}) completed" >&2
+ printf 1>&2 '\n%s\n' "Tool $tool $action (with ${arguments:-no argument}) completed"
fi
)
}
@@ -125,7 +125,7 @@ tool_action_check() {
if ! tool_check "$tool"
then
- printf '%s\n' "Tool $tool check failed" >&2
+ printf 1>&2 '%s\n' "Tool $tool check failed"
return 1
fi
@@ -138,7 +138,7 @@ tool_action_check() {
for tool_force in $TOOLS_FORCE
do
- if [ "$tool_force" = "$tool" ]
+ if [[ "$tool_force" = "$tool" ]]
then
return 1
fi
@@ -162,7 +162,7 @@ tool_action_helper() {
if ! tool_check "$tool"
then
- printf '%s\n' "Tool $tool check failed" >&2
+ printf 1>&2 '%s\n' "Tool $tool check failed"
return 1
fi
@@ -186,10 +186,10 @@ tool_action_arguments_recursive() {
local tool=$1
shift
- local action_helper_arguments=$( tool_action_helper "arguments" "$tool" "$@" )
+ local action_helper_arguments=$(tool_action_helper "arguments" "$tool" "$@")
local argument
- if [ $? -ne 0 ] || [ -z "$action_helper_arguments" ]
+ if [[ $? -ne 0 ]] || [[ -z "$action_helper_arguments" ]]
then
tool_action "$action" "$tool" "$@"
else
@@ -200,6 +200,25 @@ tool_action_arguments_recursive() {
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
@@ -217,7 +236,7 @@ tool_sources_path() {
for argument in "" "$@"
do
- if ! [ -z "$argument" ]
+ if [[ -n "$argument" ]]
then
path="$path/$argument"
fi
@@ -244,7 +263,7 @@ tool_usage_actions() {
fi
done
- if [ $# -gt 0 ]
+ if [[ $# -gt 0 ]]
then
printf '\n%s\n' 'Specific actions:'
@@ -270,10 +289,10 @@ tool_usage_arguments_recursive() {
local spacing=$1
shift
- local action_helper_arguments=$( tool_action_helper "arguments" "$tool" "$@" )
+ local action_helper_arguments=$(tool_action_helper "arguments" "$tool" "$@")
local argument
- if ! [ -z "$action_helper_arguments" ]
+ if [[ -n "$action_helper_arguments" ]]
then
printf '%s\n' "$action_helper_arguments" | while read argument
do
@@ -291,19 +310,19 @@ tool_file_path() {
local file=$1
shift
- local tool_path=$( tool_path "$tool" )
+ local tool_path=$(tool_path "$tool")
local path="$tool_path/$directory"
local argument
local file_path
for argument in "" "$@"
do
- if ! [ -z "$argument" ]
+ if [[ -n "$argument" ]]
then
path="$path/$argument"
fi
- if ! [ -f "$path/$file" ]
+ if ! [[ -f "$path/$file" ]]
then
continue
fi
@@ -311,7 +330,7 @@ tool_file_path() {
file_path="$path/$file"
done
- if [ -z "$file_path" ]
+ if [[ -z "$file_path" ]]
then
return 1
fi
@@ -320,15 +339,15 @@ tool_file_path() {
}
tool_file_test() {
- local file_path=$( tool_file_path "$@" )
+ local file_path=$(tool_file_path "$@")
test -f "$file_path"
}
tool_file_contents() {
- local file_path=$( tool_file_path "$@" )
+ local file_path=$(tool_file_path "$@")
- if [ -f "$file_path" ]
+ if [[ -f "$file_path" ]]
then
cat "$file_path"
fi
@@ -342,21 +361,21 @@ tool_file_contents_herit() {
local file=$1
shift
- local tool_path=$( tool_path "$tool" )
+ local tool_path=$(tool_path "$tool")
local path="$tool_path/$directory"
local argument
local file_path
for argument in "" "$@"
do
- if ! [ -z "$argument" ]
+ if [[ -n "$argument" ]]
then
path="$path/$argument"
fi
file_path="$path/$file"
- if ! [ -f "$file_path" ]
+ if ! [[ -f "$file_path" ]]
then
continue
fi