bootstrap help and version list

This commit is contained in:
2024-07-21 05:01:40 +03:00
parent 5c1b063399
commit 0b5eed8b4c
4 changed files with 77 additions and 25 deletions

View File

@@ -1,5 +1,5 @@
#!/usr/bin/env bash
CBUILD_BOOTSTRAP_VERSION=1.0.0
CBUILD_BOOTSTRAP_VERSION=1.0.1
set -eo pipefail
function version_parse {
@@ -29,29 +29,56 @@ function exec_script_line {
eval "$line_str"
}
function print_version_list {
dir_local="$HOME/.local/share/cbuild"
dir_global="/usr/local/share/cbuild"
files=""
if [ -d "$dir_local" ]; then
files+="$(find $dir_local -name 'CBUILD_VERSION')"
fi
if [ -d "$dir_global" ]; then
files+="$(find $dir_global -name 'CBUILD_VERSION')"
fi
for f in $files; do
cat $f | sed '$a\'
done | sort -V
}
function print_help {
echo "cbuild-bootstrap v$CBUILD_BOOTSTRAP_VERSION"
echo "Script that launches a specific cbuild version selected by user or defined in a project config."
echo "Usage: cbuild [OPTIONS]"
echo "Options:"
echo " -h, --help Show this message"
echo " -v, --version Shows version"
echo " -c, --config FILE Set project config file path (default=./project.config)"
echo " --list-versions Shows list of installed cbuild versions"
}
# parse command line arguments
project_config_path="./project.config"
args=($@)
args_count=${#args[@]}
i=0
function get_next_arg {
i=$((i+1))
safeprint "${args[i]}"
}
if [ $args_count -eq 0 ]; then
print_help
fi
while [ $i -lt $args_count ]
do
case "${args[i]}" in
'-v' | '--version')
echo "cbuild-bootstrap v$CBUILD_BOOTSTRAP_VERSION"
;;
'-c' | '--config')
project_config_path="$(get_next_arg)"
'-h' | '--help')
print_help
;;
'-n' | '--new-project')
echo "enter project cbuild version (example: 2.1.0)"
read -r CBUILD_VERSION
'-c' | '--config')
i=$((i+1))
project_config_path="${args[i]}"
;;
'--list-versions')
print_version_list
exit 0
;;
*)
;;
@@ -59,9 +86,21 @@ do
i=$((i+1))
done
# read version from project config if not specified
if [ -z "$CBUILD_VERSION" ]; then
exec_script_line "$project_config_path" 2
if [ -f "$project_config_path" ]; then
# read version from project config
exec_script_line "$project_config_path" 2
else
echo "project config not found"
echo "list of installed cbuild versions:"
versions=$(print_version_list)
echo "$versions"
latest_version=$(echo "$versions" | tail -n 1)
echo "select version (default=$latest_version):"
read -r CBUILD_VERSION
[ -z "$CBUILD_VERSION" ] && CBUILD_VERSION=$latest_version
fi
fi
version_parse "$CBUILD_VERSION"