1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
#!/bin/bash
show_help() {
echo "usage: spread-manager set-manual [--project-path <PROJECT-PATH>] <TEST-PATH...>"
echo " spread-manager unset-manual [--project-path <PROJECT-PATH>] <TEST-PATH...>"
echo " spread-manager reset-manual [--project-path <PROJECT-PATH>] <TEST-PATH...>"
echo ""
echo "Tool used to help with functions that are not already implemented in spread"
}
_check_project_path() {
local project_path="$1"
if [ -z "$project_path" ]; then
echo "spread-manager: project path cannot be empty"
exit 1
fi
if [ ! -d "$project_path" ]; then
echo "spread-manager: project path \"$project_path\" has to be a directory"
exit 1
fi
if [ ! -f "$project_path/spread.yaml" ]; then
echo "spread-manager: project spread file \"$project_path/spread.yaml\" does not exist"
exit 1
fi
}
_check_test_paths() {
local project_path="$1"
shift
# shellcheck disable=SC2124
local test_paths="$@"
if [ -z "$test_paths" ]; then
echo "spread-manager: test path cannot be empty"
exit 1
fi
for task_path in $test_paths; do
_check_test_path "$project_path" "$task_path"
done
}
_check_test_path() {
local project_path="$1"
local test_path="$2"
if [ -z "$test_path" ]; then
echo "spread-manager: test path cannot be empty"
exit 1
fi
if [ ! -d "${project_path}/${test_path}" ]; then
echo "spread-manager: test path \"${project_path}/${test_path}\" has to be a directory"
exit 1
fi
if [ ! -f "${project_path}/${test_path}/task.yaml" ]; then
echo "spread-manager: test task \"${project_path}/${test_path}/task.yaml\" does not exist"
exit 1
fi
}
_set_manual_value() {
local task_path=$1
local manual_value=$2
# Update the manual property
if grep -E "^manual:" "$task_path"; then
sed -i -e "s/^manual:.*/manual: $manual_value/g" "$task_path"
else
echo "manual: $manual_value" >> "$task_path"
fi
}
set_manual() {
local project_path="$1"
shift
# shellcheck disable=SC2124
local test_paths="$@"
_check_project_path "$project_path"
test_paths="$(echo "$test_paths" | tr ',' ' ')"
_check_test_paths "$project_path" "$test_paths"
for test_path in $test_paths; do
local task_path
task_path="$project_path/$test_path/task.yaml"
# Backup the task
cp "$task_path" "$task_path.back"
_set_manual_value "$task_path" true
done
}
unset_manual() {
local project_path="$1"
shift
# shellcheck disable=SC2124
local test_paths="$@"
_check_project_path "$project_path"
test_paths="$(echo "$test_paths" | tr ',' ' ')"
_check_test_paths "$project_path" "$test_paths"
for test_path in $test_paths; do
local task_path
task_path="$project_path/$test_path/task.yaml"
# Backup the task
cp "$task_path" "$task_path.back"
_set_manual_value "$task_path" false
done
}
reset_manual() {
local project_path="$1"
shift
# shellcheck disable=SC2124
local test_paths="$@"
_check_project_path "$project_path"
test_paths="$(echo "$test_paths" | tr ',' ' ')"
_check_test_paths "$project_path" "$test_paths"
for test_path in $test_paths; do
local task_path
task_path="$project_path/$test_path/task.yaml"
if [ -f "$task_path.back" ]; then
mv "$task_path.back" "$task_path"
else
echo "spread-manager: test task backup does not exist \"$task_path.back\""
exit 1
fi
done
}
main() {
if [ $# -eq 0 ]; then
show_help
exit 0
fi
local subcommand="$1"
local action=
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
show_help
exit 0
else
action=$(echo "$subcommand" | tr '-' '_')
shift
fi
if [ -z "$(declare -f "$action")" ]; then
echo "spread-manager: no such command: $subcommand" >&2
show_help
exit 1
fi
local project_path
if [ $# -gt 0 ]; then
if [[ "$action" =~ .*_manual ]]; then
project_path="$(pwd)"
if [ "$1" == "--project-path" ]; then
project_path="$2"
shift 2
fi
"$action" "$project_path" "$@"
else
"$action" "$@"
fi
fi
}
main "$@"
|