This commit is contained in:
2024-07-19 01:56:33 +03:00
parent f4c12e9b0e
commit 4fc62f65b4
6 changed files with 153 additions and 47 deletions

View File

@@ -1,27 +1,29 @@
#!/usr/bin/env bash
INSTALLED_CBUILD_VERSION=2.1.0
# set \t size to 4 spaces
tabs 4
# exit on errors
set -eo pipefail
INSTALLED_CBUILD_VERSION=2.1.0
function version_parse {
local v="$1"
local value="$1"
var_name="$2"
IFS_backup="$IFS"
IFS='.'
v_array=($v)
local v_array=($value)
IFS="$IFS_backup"
version_major=${v_array[0]}
version_minor=${v_array[1]}
version_patch=${v_array[2]}
eval ${var_name}_version_major=${v_array[0]}
eval ${var_name}_version_minor=${v_array[1]}
eval ${var_name}_version_patch=${v_array[2]}
}
version_parse $INSTALLED_CBUILD_VERSION
version_parse $INSTALLED_CBUILD_VERSION installed
if [ -z "$CBUILD_INSTALL_DIR" ]; then
CBUILD_INSTALL_DIR="~/.local/share/cbuild/${version_major}.${version_minor}"
CBUILD_INSTALL_DIR="$HOME/.local/share/cbuild/${installed_version_major}.${installed_version_minor}"
if [ ! -f "$CBUILD_INSTALL_DIR/cbuild.sh" ]; then
CBUILD_INSTALL_DIR="/usr/local/share/cbuild/${version_major}.${version_minor}"
CBUILD_INSTALL_DIR="/usr/local/share/cbuild/${installed_version_major}.${installed_version_minor}"
if [ ! -f "$CBUILD_INSTALL_DIR/cbuild.sh" ]; then
echo "CBUILD_INSTALL_DIR '$CBUILD_INSTALL_DIR' doesn't exist"
exit 1
@@ -52,6 +54,7 @@ function print_help {
myprint " -c, --config FILE Set project config file path (default=./project.config)"
}
# parse command line arguments
project_config_path="./project.config"
args=($@)
args_count=${#args[@]}
@@ -74,14 +77,11 @@ do
exit 0
;;
'-v' | '--version')
myprint $INSTALLED_CBUILD_VERSION
myprint "cbuild v$INSTALLED_CBUILD_VERSION"
exit 0
;;
'-c' | '--config')
i=$((i+1))
project_config_path="${args[i]}"
myprint "<$project_config_path>"
exit 0
project_config_path="$(get_next_arg)"
;;
'-n' | '--new-project')
new_project_dir="$(get_next_arg)"