From e07d33c852e9bda8c6cf237ecfe865784a09d971 Mon Sep 17 00:00:00 2001 From: Dimitri Gilbert Date: Wed, 27 Sep 2023 11:50:03 +0200 Subject: [PATCH] project webserver now replacing parseArger with program name --- bin/_project/webserver | 37 ++++++++++++++++++++----------------- bin/project | 2 +- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/bin/_project/webserver b/bin/_project/webserver index 0218d0d..9f58c33 100755 --- a/bin/_project/webserver +++ b/bin/_project/webserver @@ -3,6 +3,7 @@ # @parseArger-help "create web server for a project" --option "help" --short-option "h" # @parseArger-verbose --option "verbose" --level "0" --quiet-option "quiet" # @parseArger-declarations +# @parseArger pos name "program name" # @parseArger-declarations-end # @parseArger-utils @@ -30,6 +31,7 @@ begins_with_short_option() # POSITIONALS ARGUMENTS _positionals=(); _optional_positionals=(); +_arg_name=""; # OPTIONALS ARGUMENTS # FLAGS _verbose_level="0"; @@ -43,8 +45,9 @@ print_help() if [[ "$_helpHasBeenPrinted" == "1" ]]; then _helpHasBeenPrinted=0; echo -e "create web server for a project:" + echo -e " name: program name" echo -e "Usage : - $0"; + $0 "; fi } @@ -55,28 +58,28 @@ log() { if [ "${_arg_level}" -le "${_verbose_level}" ]; then case "$_arg_level" in -3) - _arg_COLOR=""; + _arg_COLOR="\033[0;31m"; ;; -2) - _arg_COLOR=""; + _arg_COLOR="\033[0;33m"; ;; -1) - _arg_COLOR=""; + _arg_COLOR="\033[1;33m"; ;; 1) - _arg_COLOR=""; + _arg_COLOR="\033[0;32m"; ;; 2) - _arg_COLOR=""; + _arg_COLOR="\033[1;36m"; ;; 3) - _arg_COLOR=""; + _arg_COLOR="\033[0;36m"; ;; *) - _arg_COLOR=""; + _arg_COLOR="\033[0m"; ;; esac - echo -e "${_arg_COLOR}${_arg_msg}"; + echo -e "${_arg_COLOR}${_arg_msg}\033[0m"; fi } @@ -133,13 +136,12 @@ parse_commandline() handle_passed_args_count() { - local _required_args_string="" - if [ "${_positionals_count}" -gt 0 ] && [ "$_helpHasBeenPrinted" == "1" ];then - _PRINT_HELP=yes die "FATAL ERROR: There were spurious positional arguments --- we expect at most 0 (namely: $_required_args_string), but got ${_positionals_count} (the last one was: '${_last_positional}'). - ${_positionals[*]}" 1 + local _required_args_string="name" + if [ "${_positionals_count}" -gt 1 ] && [ "$_helpHasBeenPrinted" == "1" ];then + _PRINT_HELP=yes die "FATAL ERROR: There were spurious positional arguments --- we expect at most 1 (namely: $_required_args_string), but got ${_positionals_count} (the last one was: '${_last_positional}').\n\t${_positionals[*]}" 1 fi - if [ "${_positionals_count}" -lt 0 ] && [ "$_helpHasBeenPrinted" == "1" ];then - _PRINT_HELP=yes die "FATAL ERROR: Not enough positional arguments - we require at least 0 (namely: $_required_args_string), but got only ${_positionals_count}. + if [ "${_positionals_count}" -lt 1 ] && [ "$_helpHasBeenPrinted" == "1" ];then + _PRINT_HELP=yes die "FATAL ERROR: Not enough positional arguments - we require at least 1 (namely: $_required_args_string), but got only ${_positionals_count}. ${_positionals[*]}" 1; fi } @@ -148,7 +150,7 @@ handle_passed_args_count() assign_positional_args() { local _positional_name _shift_for=$1; - _positional_names=""; + _positional_names="_arg_name "; shift "$_shift_for" for _positional_name in ${_positional_names};do test $# -gt 0 || break; @@ -164,6 +166,7 @@ print_debug() # shellcheck disable=SC2145 echo "DEBUG: $0 $@"; + echo -e "\tname: ${_arg_name}"; } @@ -187,4 +190,4 @@ trap on_interrupt INT; # print_debug "$@" # @parseArger-end -cp "${_SCRIPT_DIR}/../../utils/webserver" "utils/webserver"; +sed 's/\/parseArger/\/'"$_arg_name"'/g' "${_SCRIPT_DIR}/../../utils/webserver" > "utils/webserver"; diff --git a/bin/project b/bin/project index 0850986..fb61547 100755 --- a/bin/project +++ b/bin/project @@ -619,6 +619,6 @@ else if [ "$_arg_web_server" == "on" ]; then log "Generating web server" 4; - "$_SCRIPT_DIR/_project/webserver"; + "$_SCRIPT_DIR/_project/webserver" "$_arg_name"; fi fi