Skip to content

Commit

Permalink
feat (EFDE): #15 Add features and general improvements
Browse files Browse the repository at this point in the history
- Efde.Tasks
  - Fix main bin scope
  - Add complete interaction menu
    - More info
    - Global configs (CLI_SHOW_CLI, CLI_SHOW_OUTPUT)
    - Report on Github (Bugs, Improvents, New Features, others)
    - Update EFDE
    - Uninstall EFDE
  - Fix Implementation
- Common.Task
  - Fix command_line
  - Feat Remove Directory
  - Feat Remove File
  - Fix Menu Management
  - Message fixes
  - Feat message as tree
  - Fix propmt
  • Loading branch information
mmaximo33 committed Jan 9, 2024
1 parent 7c5bbd6 commit b62bc01
Show file tree
Hide file tree
Showing 16 changed files with 375 additions and 218 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ To **install** EFDE, you should run the install script. To do that, you may eith

```sh
curl -o- https://raw.githubusercontent.com/mmaximo33/efde/15-migrate-to-full-bash/bin/install.sh | bash

```
```sh
wget -qO- https://raw.githubusercontent.com/mmaximo33/efde/15-migrate-to-full-bash/bin/install.sh | bash
```
#### What will happen in the installation process?
Expand Down
30 changes: 13 additions & 17 deletions bin/efde.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@
set -euo pipefail
# Debug mode
EFDE_MOD_DEBUG=false # Messages debug
EFDE_MOD_DEV=true # MMTodo: Prepared for create tmps
EFDE_CFG_SHOW_CLI=true #show COMMANDLINE
declare -gA GLOBAL_EFDE_CONFIG=(
[CLI_SHOW_DEFAULT]=true # Omite configuraciones personalizadas
[CLI_SHOW_CLI]=true #
[CLI_SHOW_OUTPUT]=false
)
EFDE_MOD_DEV=false # MMTodo: Prepared for create tmps
declare -gA GLOBAL_EFDE_CONFIG


GLOBAL_RUN_EFDE=$([ "$EFDE_MOD_DEBUG" = "true" ] && echo "e2" || echo "efde")
GLOBAL_RUN_EFDE=$([ "$EFDE_MOD_DEV" = "true" ] && echo "e2" || echo "efde")

[[ $(echo "$@" | grep -oP '(?<=--debug=)[^ ]+') = "true" && "$EFDE_MOD_DEBUG" = "false" ]] && EFDE_MOD_DEBUG=true

Expand All @@ -35,10 +30,6 @@ init_dirs()
resolve_absolute_dir
export PATH_CONSOLE="${EFDE_PATH_INSTALL}/console"
export PATH_BIN="${EFDE_PATH_INSTALL}/bin"

# export COMMANDS_DIR="${ABSOLUTE_PATH}/console/commands"
# export TASKS_DIR="${ABSOLUTE_PATH}/console/tasks"
# export PROPERTIES_DIR="${EFDE_PATH_INSTALL}/console/common/properties"
}

init_dirs
Expand All @@ -50,15 +41,20 @@ menu_main(){

menu_implementation(){
local PATH_ENV=$(efde.tasks.implemention.get_current_path_env_file)
variables_string="$(efde.tasks.config.load_variables_from_file ${PATH_ENV})"
# Evaluar la cadena de variables
eval "$variables_string"
RUN_FUNCTION_IMPLEMENTATION_MAIN= "$IMPLEMENTION.tasks.menu.main"
local IMPLEMENTION=$(common.tasks.env_variable.get_variable "IMPLEMENTION" "$PATH_ENV")


${RUN_FUNCTION_IMPLEMENTATION_MAIN}
RUN_FUNCTION_IMPLEMENTATION_MAIN="$IMPLEMENTION.tasks.menu.main"
if common.tasks.module.exists_function "${RUN_FUNCTION_IMPLEMENTATION_MAIN}"; then
${RUN_FUNCTION_IMPLEMENTATION_MAIN}
fi
# else
# ${GLOBAL_RUN_EFDE}
# fi
}

main(){
efde.tasks.config.check_config
if ! efde.tasks.implemention.has_folder_implementation ; then
menu_main
fi
Expand Down
2 changes: 1 addition & 1 deletion bin/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@
efde_project_install_from_git

efde_reset
efde_confirm_default_yes "You want to run efde --help now?" && efde
}

efde_project_install_from_git() {
Expand All @@ -310,7 +311,6 @@
efde_create_bin

efde_print_step end
efde_confirm_default_yes "You want to run efde --help now?" && efde --help
}

efde_project_install_existing_folder(){
Expand Down
18 changes: 8 additions & 10 deletions console/common/tasks/command_line
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ set -euo pipefail

_mod_.run() {
if [ "$#" -ne 3 ]; then
local USED=""
USED+="Error: Three parameters are required:\n"
USED+=" - FORCE_SHOW_CLI FORCE_SHOW_OUTPUT COMMAND_LINE\n"
USED+="\n parameters:\n ${@}\n"
USED+="\n Example:\n"
USED+=" - $FUNCNAME FORCE_SHOW_CLI=true FORCE_SHOW_OUTPUT=true COMMAND_LINE\n"
USED+=" - $FUNCNAME 1 0 'cd folder'"
common.tasks.message.danger $USED
local USE=""
USE+="Error: Three parameters are required:\n"
USE+=" - FORCE_SHOW_CLI FORCE_SHOW_OUTPUT COMMAND_LINE\n"
USE+="\n parameters:\n ${@}\n"
USE+="\n Example:\n"
USE+=" - $FUNCNAME FORCE_SHOW_CLI=true FORCE_SHOW_OUTPUT=true COMMAND_LINE\n"
USE+=" - $FUNCNAME 1 0 'cd folder'"
common.tasks.message.danger $USE
return 1
fi

Expand All @@ -23,8 +23,6 @@ _mod_.run() {
if [ "${GLOBAL_EFDE_CONFIG['CLI_SHOW_DEFAULT']}" = "false" ]; then
FORCE_SHOW_CLI=${GLOBAL_EFDE_CONFIG['CLI_SHOW_CLI']}
FORCE_SHOW_OUTPUT=${GLOBAL_EFDE_CONFIG['CLI_SHOW_OUTPUT']}
#[ "${GLOBAL_EFDE_CONFIG['CLI_SHOW_CLI']}" = "true" ] && FORCE_SHOW_CLI=true
#[ "${GLOBAL_EFDE_CONFIG['CLI_SHOW_OUTPUT']}" = "true" ] && FORCE_SHOW_OUTPUT=true
fi

if [ "${FORCE_SHOW_CLI}" = "true" ]; then
Expand Down
35 changes: 34 additions & 1 deletion console/common/tasks/directory
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,37 @@ _mod_.exists() {

_mod_.create_recursive() {
mkdir -p "$1"
}
}

# USE
#
# common.tasks.directory.remove "$PATH"
_mod_.remove() {
local FORCE PATH
FORCE=false
[[ "$1" == "force" ]] && { force=true; shift; path="$1"; }

local PATH="$1"
if [[ -z "$PATH" ]]; then
common.tasks.message.info "Usage: _mod_.remove [force] <path directory>"
return 1
fi

if [[ ! -e "$PATH" ]]; then
common.tasks.message.danger "Error: Path '$PATH' does not exist."
return 1
fi

local CONFIRM="Delete FOLDER"
local CONFIRM_COLOR=$(common.tasks.message.msg_color danger "$CONFIRM")
local QUESTION=$(common.tasks.message.msg_color warning "Confirm this action by writing '$CONFIRM_COLOR'")
common.tasks.message.warning "We are about to delete the directory $(common.tasks.message.msg_color info $PATH)"
local RESPONSE=$(common.tasks.prompt.request_input "$QUESTION")
if [[ "$RESPONSE" == "$CONFIRM" ]]; then
[[ "$FORCE" == true ]] && /bin/rm -rf "$PATH" || /bin/rm -r "$PATH"
common.tasks.message.success "Removed: $PATH"
else
common.tasks.message.warning "Removal aborted."
fi
}

133 changes: 77 additions & 56 deletions console/common/tasks/env_variable
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
#!/usr/bin/env bash
set -euo pipefail

_mod_.set_variable() {
_mod_.pila_llamada(){
local caller_info
caller_info=$(caller 0)
echo $caller_info
echo $(echo "$caller_info" | awk '{print $3}')
}

# USE
#
# common.tasks.env_variable.set_variable "$KEY" "$VALUE" "$PATH_FILE"
# common.tasks.env_variable.set_variable $1 $2 $FILE
_mod_.set_variable() {
if [ "$#" -ne 3 ]; then
echo "Error: Se requieren tres parámetros: key, value, file"
common.tasks.message.danger "[Error]: Se requieren tres parámetros: key, value, file \n" >&2
return 1
fi

Expand All @@ -29,7 +39,7 @@ _mod_.set_variable() {

_mod_.get_variable() {
if [ "$#" -ne 2 ]; then
echo "Error: Se requieren dos parámetros: key, file"
common.tasks.message.danger "[Error]: Two parameters required: $KEY, $FILE \n" >&2
return 1
fi

Expand All @@ -44,64 +54,75 @@ _mod_.get_variable() {
value=$(echo "$value" | sed 's/^"\(.*\)"$/\1/')
echo -n "$value"
else
echo "No encontrado"
common.tasks.message.danger "No encontrado: " >&2
fi
else
echo "Error: El archivo $file no existe."
return 1
#echo $(common.tasks.module.debug_function_moment) >&2
common.tasks.message.debug "[Error]: File $file does not exist " >&2
common.tasks.message.debug "- Function: $FUNCNAME" >&2
common.tasks.message.debug "- CallFunction: $FUNCNAME" >&2
return 0
fi
}


# USAGED
# Call:
# SETUP_ENVIRONMENT=(
# [NAME]="MyName"
# [CREATE_AT]="2000-01-01"
# [IMPLEMENTION]="efde"
# )
# VAR_STRING="$(_mod_.prepare_string_to_env SETUP_ENVIRONMENT)"
#
# echo -e "$VAR_STRING" > "$PATH_FILE"
#
## USAGED
## Call:
## SETUP_ENVIRONMENT=(
## [NAME]="MyName"
## [CREATE_AT]="2000-01-01"
## [IMPLEMENTION]="efde"
## )
## VAR_STRING="$(_mod_.prepare_string_to_env SETUP_ENVIRONMENT)"
##
## echo -e "$VAR_STRING" > "$PATH_FILE"
##
## Response:
## 'NAME="MyName"\nCREATE_AT="2000-01-01"\nIMPLEMENTION="efde"'
#_mod_.prepare_string_to_env(){
# local -n env_array=$1
# local env_str=""
#
# for key in "${!env_array[@]}"; do
# value="${env_array[$key]}"
# env_str+="\n$key=\"$value\""
# done
#
# env_str="${env_str:2}" # Remove firts \n
#
# echo "$env_str"
#}
#
#_mod_.load_variables_from_file() {
# local file_path="$1"
# local variables=""
#
# if [ -f "$file_path" ]; then
# # Leer el archivo y construir la cadena de variables
# while IFS='=' read -r key value; do
# # Eliminar espacios en blanco alrededor de la clave y el valor
# key=$(echo "$key" | sed 's/^[ \t]*//;s/[ \t]*$//')
# value=$(echo "$value" | sed 's/^[ \t]*//;s/[ \t]*$//')
#
# # Agregar la variable a la cadena
# variables+="$key=\"$value\" "
# done < "$file_path"
# Response:
# 'NAME="MyName"\nCREATE_AT="2000-01-01"\nIMPLEMENTION="efde"'
_mod_.prepare_string_to_env(){
local -n env_array=$1
local env_str=""

for key in "${!env_array[@]}"; do
value="${env_array[$key]}"
env_str+="\n$key=\"$value\""
done

env_str="${env_str:2}" # Remove firts \n

echo "$env_str"
}

# USE
#
# # Eliminar posibles espacios en blanco al final
# variables=$(echo "$variables" | sed 's/[ \t]*$//')
# variables_string="$(common.tasks.env_variable.load_variables_from_file ${PATH_ENV})"
# # Evaluar la cadena de variables
# eval "$variables_string"
# RUN_FUNCTION_IMPLEMENTATION_MAIN= "$IMPLEMENTION.tasks.menu.main"
#
# # Devolver la cadena de variables
# echo "$variables"
# else
# echo "Error: El archivo $file_path no existe."
# return 1
# fi
#}
# $IMPLEMENTION="TEST"
_mod_.load_variables_from_file() {
local file_path="$1"
local variables=""

if [ -f "$file_path" ]; then
# Leer el archivo y construir la cadena de variables
while IFS='=' read -r key value; do
# Eliminar espacios en blanco alrededor de la clave y el valor
key=$(echo "$key" | sed 's/^[ \t]*//;s/[ \t]*$//')
value=$(echo "$value" | sed 's/^[ \t]*//;s/[ \t]*$//')

# Agregar la variable a la cadena
variables+="$key=\"$value\" "
done < "$file_path"

# Eliminar posibles espacios en blanco al final
variables=$(echo "$variables" | sed 's/[ \t]*$//')

# Devolver la cadena de variables
echo "$variables"
else
common.tasks.message.danger "[Error]: File $file_path does not exist" >&2
return 1
fi
}
34 changes: 33 additions & 1 deletion console/common/tasks/file
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,36 @@ set -euo pipefail

_mod_.exists() {
[ -e "$1" ]
}
}

# USE
#
# common.tasks.file.remove "$PATH_FILE"
_mod_.remove() {
local FORCE PATH
FORCE=false
[[ "$1" == "force" ]] && { force=true; shift; path="$1"; }

local PATH="$1"
if [[ -z "$PATH" ]]; then
common.tasks.message.info "Usage: _mod_.remove [force] <path file>"
return 1
fi

if [[ ! -e "$PATH" ]]; then
common.tasks.message.danger "Error: Path file '$PATH' does not exist."
return 1
fi

local CONFIRM="Delete FILE"
local CONFIRM_COLOR=$(common.tasks.message.msg_color danger "$CONFIRM")
local QUESTION=$(common.tasks.message.msg_color warning "Confirm this action by writing '$CONFIRM_COLOR'")
common.tasks.message.warning "We are about to delete the file $(common.tasks.message.msg_color info $PATH)"
local RESPONSE=$(common.tasks.prompt.request_input "$QUESTION")
if [[ "$RESPONSE" == "$CONFIRM" ]]; then
[[ "$FORCE" == true ]] && /bin/rm -f "$PATH" || /bin/rm "$PATH"
common.tasks.message.success "Removed: $PATH"
else
common.tasks.message.warning "Removal aborted."
fi
}
8 changes: 4 additions & 4 deletions console/common/tasks/menu
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ _mod_.print_menu(){
if [[ ${#values[@]} -ge 2 ]]; then
titulo=${values[1]}
description=$([ "$EFDE_MOD_DEBUG" = "true" ] && echo ${values[0]} || echo ${values[2]})
printf "%-0s. %-40s %s\n" "$i" "$titulo" "$description"
printf "%-0s. %-35s %s\n" "$i" "$titulo" "$description"
else
common.tasks.message.warning "Opción inválida: $option"
common.tasks.message.warning "Invalid option: $option"
fi
done

common.tasks.message.info "\nPress R to return | Q to quit | I for info"

choice=$(common.tasks.prompt.request_input "$(common.tasks.message.success "Enter the option number:") ")
choice=$(common.tasks.prompt.request_input "$(common.tasks.message.success "Enter the option number:")")

if [[ $choice =~ ^[0-9]+$ && $choice -ge 0 && $choice -le $(( ${#options[@]} -1 )) ]]; then
MENU_RESPONSE_CHOICE=$choice
Expand All @@ -56,7 +56,7 @@ _mod_.print_menu(){
[[ "$choice" == "q" ]] && exit 0
[[ "$choice" == "r" ]] && { common.console_clear; ${GLOBAL_MENU_RESPONSE_ARRAY_ASOCITIVE['function_old']}; return; }
common.console_clear
common.tasks.message.danger "La opción '$choice' no está en la lista."
common.tasks.message.danger "The '$choice' option is not in the list."
_mod_.print_menu "$question" "${options[@]}"
fi
}
Expand Down
Loading

0 comments on commit b62bc01

Please sign in to comment.