fixed myprint and added --version

This commit is contained in:
Timerix 2024-07-12 02:09:10 +03:00
parent 9b1bbffbc4
commit 0ebc1c47ee
3 changed files with 12 additions and 4 deletions

View File

@ -3,6 +3,7 @@
+ deleted makefile (call `./cbuild.sh` or installed `cbuild`)
+ added command line arguments:
+ `--help`
+ `--version`
+ `--current-config`
+ `--default-config`
+ `--new-project`

View File

@ -14,7 +14,7 @@ fi
function include {
local script_path="$1"
if [[ "$script_path" == cbuild/* ]]; then
script_path="$CBUILD_INSTALL_DIR/$(safeprint $script_path | sed 's,^cbuild/,,')"
script_path="$CBUILD_INSTALL_DIR/$(echo $script_path | sed 's,^cbuild/,,')"
fi
# echp "including script $script_path"
. "$script_path"
@ -31,8 +31,11 @@ include "cbuild/functions.sh"
include "cbuild/config.sh"
function print_help_and_exit {
myprint "cbuild v$INSTALLED_CBUILD_VERSION"
myprint "C/C++ project build system written in bash."
myprint "Usage: cbuild [OPTIONS] [TASK]"
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)"
@ -60,6 +63,10 @@ do
'-h' | '--help')
print_help_and_exit
;;
'-v' | '--version')
myprint $INSTALLED_CBUILD_VERSION
exit 0
;;
'-c' | '--current-config')
i=$((i+1))
current_config_path="${args[i]}"

View File

@ -10,15 +10,15 @@ BLUE='\033[0;94m'
PURPLE='\033[0;95m'
CYAN='\033[0;96m'
# prints text without new line
# prints text without special characters
# use it to return string values from functions
function safeprint {
printf "%s" "$@"
}
# prints text with new line and resets color
# prints text with special characters and resets color
function myprint {
safeprint "$@${GRAY}\n"
printf "${GRAY}$@${GRAY}\n"
}
# print message and exit