--new-project

This commit is contained in:
2024-07-12 02:32:59 +03:00
parent 0ebc1c47ee
commit fc833508b8
5 changed files with 44 additions and 32 deletions

View File

@@ -30,7 +30,7 @@ include "cbuild/myprint.sh"
include "cbuild/functions.sh"
include "cbuild/config.sh"
function print_help_and_exit {
function print_help {
myprint "cbuild v$INSTALLED_CBUILD_VERSION"
myprint "C/C++ project build system written in bash."
myprint "Usage: cbuild [OPTIONS] [TASK]"
@@ -39,17 +39,16 @@ function print_help_and_exit {
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)"
exit 0
}
current_config_path="./current.config"
default_config_path="./default.config"
args=($@)
args_len=${#args[@]}
args_count=${#args[@]}
selected_tasks_array=()
i=0
if [ $args_len -eq 0 ]; then
print_help_and_exit
if [ $args_count -eq 0 ]; then
print_help
fi
function get_next_arg {
@@ -57,15 +56,14 @@ function get_next_arg {
safeprint "${args[i]}"
}
while [ $i -lt $args_len ]
while [ $i -lt $args_count ]
do
case "${args[i]}" in
'-h' | '--help')
print_help_and_exit
print_help
;;
'-v' | '--version')
myprint $INSTALLED_CBUILD_VERSION
exit 0
;;
'-c' | '--current-config')
i=$((i+1))
@@ -84,8 +82,9 @@ do
if ask_yn "create default.config?"; then
cp "$CBUILD_INSTALL_DIR/default.config" "$new_project_dir"
project_name="$(ask 'Enter project name')"
sed -i "s,\%PROJECT_NAME\%,$project_name,g"
myprint "Enter project name: "
read -r project_name
sed -i "s,\%PROJECT_NAME\%,$project_name,g" "default.config"
fi
if ask_yn "Copy default .gitignore?"; then
cp "$CBUILD_INSTALL_DIR/.gitignore" "$new_project_dir"
@@ -129,13 +128,19 @@ function call_tasks {
print_hline "${WHITE}" "═"
}
time call_tasks "${selected_tasks_array[@]}" #2>&1 | tee cbuild.log
# remove terminal escape codes
sed -e 's/[^[:blank:][:print:]]//g' \
-e 's/\[0;[0-9][0-9]m//g' \
-e 's/\[0;[0-9]m//g' \
-e 's/\[[0-9][0-9]m//g' \
-e 's/\[[0-9]m//g' \
-e 's/ H //g' \
-e 's/\[3gH //g' \
-i cbuild.log
selected_tasks_count=${#selected_tasks_array[@]}
if [ $selected_tasks_count -gt 0 ]; then
time call_tasks "${selected_tasks_array[@]}" #2>&1 | tee cbuild.log
fi
if [ -f cbuild.log ]; then
# remove terminal escape codes
sed -e 's/[^[:blank:][:print:]]//g' \
-e 's/\[0;[0-9][0-9]m//g' \
-e 's/\[0;[0-9]m//g' \
-e 's/\[[0-9][0-9]m//g' \
-e 's/\[[0-9]m//g' \
-e 's/ H //g' \
-e 's/\[3gH //g' \
-i cbuild.log
fi