#!/usr/bin/env bash

# shellcheck shell=bash

# ``````````````````````````````````````````````````````````````````````````````
# Function name: cli_show()
#
# Description:
#   Show help in cli.
#
# Usage:
#   cli_show
#
# Examples:
#   cli_show
#

function cli_show() {

  # shellcheck disable=SC2034
  local _FUNCTION_ID="cli_show"
  local _STATE=0

  _module_commands_count=0
  _module_commands_count_all=0

  # shellcheck disable=SC2034,SC2154
  _static_menu="${_tmp}/.static.menu"

  # shellcheck disable=SC2154
  _modules_count=$(find "${_modules}" -name '*.mod' | wc -l)

  : >"${_static_menu}"

  printf "\\n\\e[1;38m    %-25.25s %-12.12s %s\\e[m\\n    %-25.25s %-12.12s %s\\n\\n" \
         "Module" \
         "Profiles" \
         "Description" \
         "------" \
         "--------" \
         "-----------" >> "${_static_menu}"

  # shellcheck disable=SC2154
  for i in "${modules_full_list[@]}" ; do

    _module_commands_count=0

    # shellcheck disable=SC2034
    _fname=$(echo "$i" | awk -v FS="(:|:)" '{print $1}')
    # shellcheck disable=SC2034
    _fpath=$(echo "$i" | awk -v FS="(:|:)" '{print $2}')

    # shellcheck disable=SC1090
    source "${_modules}/${_fpath}"

    # shellcheck disable=SC2034
    module_name="$_fname"

    "${_fname}"

    _module_commands_count=$((_module_commands_count + ${#_module_commands[*]}))
    _module_commands_count_all=$((_module_commands_count_all + _module_commands_count))

    printf "    \\e[1;36m%-25.25s\\e[m \\e[1;33m%-12.12s\\e[m %s\\n" \
           "$_fname" "$_module_commands_count" "$description" >> "${_static_menu}"

  done

  printf "\\n    %s:  \\e[1;39m%s\\e[m\\n    %s: \\e[1;39m%s\\e[m\\n\\n" \
         "All Modules" "$_modules_count" \
         "All Profiles" "$_module_commands_count_all" >> "${_static_menu}"

  cat "${_static_menu}"

  : >"${_static_menu}"

  return $_STATE

}
