parse_version

This commit is contained in:
2024-07-19 00:13:12 +03:00
parent 7d60219c33
commit 4b4794e253
7 changed files with 123 additions and 85 deletions

View File

@@ -4,11 +4,29 @@ tabs 4
# exit on errors
set -eo pipefail
INSTALLED_CBUILD_VERSION=2.1.0
INSTALLED_CBUILD_VERSION=2.0.2
function version_parse {
local v="$1"
IFS_backup="$IFS"
IFS='.'
v_array=($v)
IFS="$IFS_backup"
version_major=${v_array[0]}
version_minor=${v_array[1]}
version_patch=${v_array[2]}
}
version_parse $INSTALLED_CBUILD_VERSION
if [ -z "$CBUILD_INSTALL_DIR" ]; then
CBUILD_INSTALL_DIR="/usr/local/share/cbuild"
CBUILD_INSTALL_DIR="~/.local/share/cbuild/${version_major}.${version_minor}"
if [ ! -f "$CBUILD_INSTALL_DIR/cbuild.sh" ]; then
CBUILD_INSTALL_DIR="/usr/local/share/cbuild/${version_major}.${version_minor}"
if [ ! -f "$CBUILD_INSTALL_DIR/cbuild.sh" ]; then
echo "CBUILD_INSTALL_DIR '$CBUILD_INSTALL_DIR' doesn't exist"
exit 1
fi
fi
fi
function include {
@@ -31,12 +49,10 @@ function print_help {
myprint " -h, --help Show this message"
myprint " -v, --version Shows version"
myprint " -n, --new-project [PROJ_DIR] Initialize new cbuild project directory (default=./)"
myprint " -c, --current-config FILE Set current config file path (default=./current.config)"
myprint " -d, --default-config FILE Set default config file path (default=./current.config)"
myprint " -c, --config FILE Set project config file path (default=./project.config)"
}
current_config_path="./current.config"
default_config_path="./default.config"
project_config_path="./project.config"
args=($@)
args_count=${#args[@]}
selected_tasks_array=()
@@ -55,34 +71,35 @@ do
case "${args[i]}" in
'-h' | '--help')
print_help
exit 0
;;
'-v' | '--version')
myprint $INSTALLED_CBUILD_VERSION
exit 0
;;
'-c' | '--current-config')
'-c' | '--config')
i=$((i+1))
current_config_path="${args[i]}"
myprint "<$current_config_path>"
exit
;;
'-d' | '--default-config')
default_config_path="$(get_next_arg)"
project_config_path="${args[i]}"
myprint "<$project_config_path>"
exit 0
;;
'-n' | '--new-project')
new_project_dir="$(get_next_arg)"
if [ -z "$new_project_dir" ]; then
new_project_dir="./"
new_project_dir="."
fi
if ask_yn "create default.config?"; then
cp "$CBUILD_INSTALL_DIR/default.config" "$new_project_dir"
if ask_yn "create default cbuild project config?"; then
project_config_path="$new_project_dir/project.config"
cp "$CBUILD_INSTALL_DIR/default.config" "$project_config_path"
myprint "Enter project name: "
read -r project_name
sed -i "s,\%PROJECT_NAME\%,$project_name,g" "default.config"
sed -i "s,\%PROJECT_NAME\%,$project_name,g" "$project_config_path"
myprint "${GREEN}created config at '$project_config_path'"
fi
if ask_yn "Copy default .gitignore?"; then
cp "$CBUILD_INSTALL_DIR/.gitignore" "$new_project_dir"
cp "$CBUILD_INSTALL_DIR/.gitignore" "$new_project_dir/"
fi
exit 0
;;
*)
selected_tasks_array+=(${args[i]})
@@ -92,13 +109,12 @@ do
done
function call_task {
local current_config_path="$1"
local default_config_path="$2"
local task="$3"
TASK_ARGS="$4"
local project_config_path="$1"
local task="$2"
TASK_ARGS="$3"
print_header "${CYAN}" "─" "$PROJECT/$task"
load_config "$current_config_path" "$default_config_path" "$task" true
load_config "$project_config_path" "$task" true
if [ ! -z "$PRE_TASK_SCRIPT" ]; then
myprint "${BLUE}executing ${WHITE}$TASK_SCRIPT"
@@ -116,7 +132,7 @@ function call_task {
function call_tasks {
local tasks="$@"
load_config "$current_config_path" "$default_config_path" "" false
load_config "$project_config_path" "" false
print_header "${WHITE}" "═" "$PROJECT"
project_dir="$(pwd)"
for task_str in $tasks ; do
@@ -126,7 +142,7 @@ function call_tasks {
IFS=',;'
args_array=($args_str)
IFS="$IFS_backup"
call_task "$current_config_path" "$default_config_path" "$task" "${args_array[@]}"
call_task "$project_config_path" "$task" "${args_array[@]}"
cd "$project_dir"
done
}