diff --git a/tools/modules/docs/config.docs.sh b/tools/modules/docs/config.docs.sh index fcd4dcf4..e416afef 100644 --- a/tools/modules/docs/config.docs.sh +++ b/tools/modules/docs/config.docs.sh @@ -229,58 +229,6 @@ function see_use() { echo -e "$mod_message" } -module_options+=( - ["generate_json_options,author"]="@Tearran" - ["generate_json_options,ref_link"]="" - ["generate_json_options,feature"]="generate_json" - ["generate_json_options,desc"]="Generate JSON-like object file." - ["generate_json_options,example"]="generate_json" - ["generate_json_options,status"]="review" - ["generate_json_options,doc_link"]="" -) -# -# Function to generate a JSON-like object file -# -function generate_json_options() { - echo -e "{\n\"configng-helpers\" : [" - features=() - for key in "${!module_options[@]}"; do - if [[ $key == *",feature" ]]; then - features+=("${module_options[$key]}") - fi - done - - for index in "${!features[@]}"; do - feature=${features[$index]} - desc_key="${feature},desc" - example_key="${feature},example" - author_key="${feature},author" - ref_key="${feature},ref_link" - status_key="${feature},status" - doc_key="${feature},doc_link" - author="${module_options[$author_key]}" - ref_link="${module_options[$ref_key]}" - status="${module_options[$status_key]}" - doc_link="${module_options[$doc_key]}" - desc="${module_options[$desc_key]}" - example="${module_options[$example_key]}" - echo " {" - echo " \"id\": \"$feature\"," - echo " \"Author\": \"$author\"," - echo " \"src_reference\": \"$ref_link\"," - echo " \"description\": \"$desc\"," - echo " \"command\": [ \"$example\" ]", - echo " \"status\": \"$status\"," - echo " \"doc_link\": \"$doc_link\"" - if [ $index -ne $((${#features[@]} - 1)) ]; then - echo " }," - else - echo " }" - fi - done - echo "]" - echo "}" -} module_options+=( ["generate_svg,author"]="@Tearran" @@ -530,7 +478,7 @@ module_options+=( ["see_cli_legacy,ref_link"]="" ["see_cli_legacy,feature"]="see_cli_legacy" ["see_cli_legacy,desc"]="Generate a Help message legacy cli commands." - ["see_cli_legacy,example"]="see_cli_legacy" + ["see_cli_legacy,example"]="" ["see_cli_legacy,status"]="review" ["see_cli_legacy,doc_link"]="" ) diff --git a/tools/modules/docs/generate_json_data.sh b/tools/modules/docs/generate_json_data.sh new file mode 100644 index 00000000..e48c6e73 --- /dev/null +++ b/tools/modules/docs/generate_json_data.sh @@ -0,0 +1,140 @@ + +module_options+=( + ["generate_json_options,author"]="@Tearran" + ["generate_json_options,ref_link"]="" + ["generate_json_options,feature"]="generate_json_options" + ["generate_json_options,desc"]="Generate JSON-like object file." + ["generate_json_options,example"]="" + ["generate_json_options,status"]="review" + ["generate_json_options,doc_link"]="" +) +# +# Function to generate a JSON-like object file +# +function set_json_data() { + local i=0 + + features=() + for key in "${!module_options[@]}"; do + if [[ $key == *",feature" ]]; then + features+=("${module_options[$key]}") + fi + done + + { + echo -e "[" + + for feature in "${features[@]}"; do + feature_prefix=$(echo "${feature:0:3}" | tr '[:lower:]' '[:upper:]') # Extract first 3 letters and convert to uppercase + + i=$((i + 1)) + id=$(printf "%s%03d" "$feature_prefix" "$i") # Combine prefix with padded number + + # Get keys pairs + desc_key="${feature},desc" + example_key="${feature},example" + author_key="${feature},author" + ref_key="${feature},ref_link" + status_key="${feature},status" + doc_key="${feature},doc_link" + # Get array info + author="${module_options[$author_key]}" + ref_link="${module_options[$ref_key]}" + status="${module_options[$status_key]}" + doc_link="${module_options[$doc_key]}" + desc="${module_options[$desc_key]}" + example="${module_options[$example_key]}" + + + echo " {" + echo " \"id\": \"$id\"," + echo " \"id\": \"$feature\"," + echo " \"description\": \"$desc ($feature) \"," + echo " \"command\": [ \"$feature\" ]," + echo " \"status\": \"test\"," + echo " \"condition\": \"[ -n see_ping ]\"," + echo " \"author\": \"$author\"" + if [ $i -ne ${#features[@]} ]; then + echo " }," + else + echo " }" + fi + done + echo "]" + + } | jq . +} + + +generate_json_data(){ + set_json_data | jq '[.[] | + if .id | startswith("module_") then + { + "id": .id, + "description": .description, + "command": ["see_menu " + .command[0]], # prepend see_menu to the command + "status": .status, + "condition": .condition, + "author": .author + } + elif .id | startswith("generate_") then + { + "id": .id, + "description": .description, + "command": ["show_infobox <<< " + .command[0]], # prepend see_menu to the command + "status": .status, + "condition": .condition, + "author": .author + } + else + { + "id": .id, + "description": .description, + "command": .command, + "status": .status, + "condition": .condition, + "author": .author + } + end +] | { + "menu": [ + + { + "id": "Modules", + "description": "Description ...", + "sub": [ + .[] | select(.id | startswith("module_")) + ] + }, + { + "id": "Generate", + "description": "Description ...", + "sub": [ + .[] | select(.id | startswith("generate_")) + ] + }, + { + "id": "Helpers", + "description": "Description ...", + "sub": [ + .[] | select(.id | startswith("module_") | not) + ] + } + ] +}' + +} + + + +interface_json_data() { +# Test Function + + #set_json_data > tools/json/config.temp.json + #json_file="$tools_dir/json/config.temp.json" + json_data=$(generate_json_data) + generate_top_menu "$json_data" + #generate_menu "Modules" "$json_data" + + +} diff --git a/tools/modules/functions/config_interface.sh b/tools/modules/functions/config_interface.sh index e512e6da..799d0c6a 100644 --- a/tools/modules/functions/config_interface.sh +++ b/tools/modules/functions/config_interface.sh @@ -107,6 +107,8 @@ parse_menu_items() { done < <(echo "$json_data" | jq -r '.menu[] | '${parent_id:+".. | objects | select(.id==\"$parent_id\") | .sub[]? |"}' select(.status != "Disabled") | "\(.id)\n\(.description)\n\(.condition)"' || exit 1) } + + module_options+=( ["generate_top_menu,author"]="@Tearran" ["generate_top_menu,ref_link"]="" @@ -172,7 +174,9 @@ function generate_menu() { [ -z "$OPTION" ] && break # Check if the selected option has a submenu - local submenu_count=$(jq -r --arg id "$OPTION" '.menu[] | .. | objects | select(.id==$id) | .sub? | length' "$json_file") + #local submenu_count=$(jq -r --arg id "$OPTION" '.menu[] | .. | objects | select(.id==$id) | .sub? | length' "$json_file") + local submenu_count=$(echo "$json_data" | jq -r --arg id "$OPTION" '.menu[] | .. | objects | select(.id==$id) | .sub? | length') + submenu_count=${submenu_count:-0} # If submenu_count is null or empty, set it to 0 if [ "$submenu_count" -gt 0 ]; then # If it does, generate a new menu for the submenu @@ -203,20 +207,20 @@ function execute_command() { local id=$1 # Extract commands - local commands=$(jq -r --arg id "$id" ' + local commands=$(echo "$json_data" | jq -r --arg id "$id" ' .menu[] | .. | objects | select(.id == $id) | - .command[]?' "$json_file") + .command[]?') # Check if a about exists - local about=$(jq -r --arg id "$id" ' + local about=$(echo "$json_data" | jq -r --arg id "$id" ' .menu[] | .. | objects | select(.id == $id) | - .about?' "$json_file") + .about?') # If a about exists, display it and wait for user confirmation if [[ "$about" != "null" && $INPUTMODE != "cmd" ]]; then