Skip to content

Commit

Permalink
project webserver now replacing parseArger with program name
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitriGilbert committed Sep 27, 2023
1 parent 3e1ebf7 commit e07d33c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
37 changes: 20 additions & 17 deletions bin/_project/webserver
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -30,6 +31,7 @@ begins_with_short_option()
# POSITIONALS ARGUMENTS
_positionals=();
_optional_positionals=();
_arg_name="";
# OPTIONALS ARGUMENTS
# FLAGS
_verbose_level="0";
Expand All @@ -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 <name>";
fi

}
Expand All @@ -55,28 +58,28 @@ log() {
if [ "${_arg_level}" -le "${_verbose_level}" ]; then
case "$_arg_level" in
-3)
_arg_COLOR="[0;31m";
_arg_COLOR="\033[0;31m";
;;
-2)
_arg_COLOR="[0;33m";
_arg_COLOR="\033[0;33m";
;;
-1)
_arg_COLOR="[1;33m";
_arg_COLOR="\033[1;33m";
;;
1)
_arg_COLOR="[0;32m";
_arg_COLOR="\033[0;32m";
;;
2)
_arg_COLOR="[1;36m";
_arg_COLOR="\033[1;36m";
;;
3)
_arg_COLOR="[0;36m";
_arg_COLOR="\033[0;36m";
;;
*)
_arg_COLOR="[0m";
_arg_COLOR="\033[0m";
;;
esac
echo -e "${_arg_COLOR}${_arg_msg}[0m";
echo -e "${_arg_COLOR}${_arg_msg}\033[0m";
fi
}

Expand Down Expand Up @@ -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
}
Expand All @@ -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;
Expand All @@ -164,6 +166,7 @@ print_debug()
# shellcheck disable=SC2145
echo "DEBUG: $0 $@";

echo -e "\tname: ${_arg_name}";

}

Expand All @@ -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";
2 changes: 1 addition & 1 deletion bin/project
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e07d33c

Please sign in to comment.