Skip to content

Commit

Permalink
fix syile
Browse files Browse the repository at this point in the history
  • Loading branch information
Tearran committed Dec 12, 2024
1 parent 674cfc2 commit be10d7b
Showing 1 changed file with 87 additions and 83 deletions.
170 changes: 87 additions & 83 deletions tools/modules/docs/generate_json_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,105 +16,109 @@ module_options+=(
# 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"
helpers_key="${feature},helpers"
group_key="${feature},group"
commands_key="${feature},commands"
port_key="${feature},port"
arch_key="${feature},arch"

# 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]}"
helpers="${module_options[$helpers_key]}"
group="${module_options[$group_key]}"
commands="${module_options[$commands_key]}"
port="${module_options[$port_key]}"
arch="${module_options[$arch_key]}"

echo " {"
echo " \"id\": \"$id\","
echo " \"feature\": \"$feature\","
echo " \"helpers\": \"$helpers\","
echo " \"description\": \"$desc ($feature)\","
echo " \"command\": \"$feature\","
echo " \"options\": \"$example\","
echo " \"status\": \"$status\","
echo " \"condition\": \"$feature check\","
echo " \"reference\": \"$ref_link\","
echo " \"author\": \"$author\","
echo " \"group\": \"$group\","
echo " \"commands\": \"$commands\","
echo " \"port\": \"$port\","
echo " \"arch\": \"$arch\""

if [ $i -ne ${#features[@]} ]; then
echo " },"
else
echo " }"
fi
done
echo "]"

} | jq .
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"
helpers_key="${feature},helpers"
group_key="${feature},group"
commands_key="${feature},commands"
port_key="${feature},port"
arch_key="${feature},arch"

# 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]}"
helpers="${module_options[$helpers_key]}"
group="${module_options[$group_key]}"
commands="${module_options[$commands_key]}"
port="${module_options[$port_key]}"
arch="${module_options[$arch_key]}"

echo " {"
echo " \"id\": \"$id\","
echo " \"feature\": \"$feature\","
echo " \"helpers\": \"$helpers\","
echo " \"description\": \"$desc ($feature)\","
echo " \"command\": \"$feature\","
echo " \"options\": \"$example\","
echo " \"status\": \"$status\","
echo " \"condition\": \"$feature check\","
echo " \"reference\": \"$ref_link\","
echo " \"author\": \"$author\","
echo " \"group\": \"$group\","
echo " \"commands\": \"$commands\","
echo " \"port\": \"$port\","
echo " \"arch\": \"$arch\""

if [ $i -ne ${#features[@]} ]; then
echo " },"
else
echo " }"
fi
done
echo "]"

} | jq .

}

generate_json_data(){
set_json_data | jq '[
.[] |
if (.feature | type == "string") and (.feature | startswith("module_")) then
{
"id": .id,
"description": .description,
set_json_data | jq '[
.[] |
if (.feature | type == "string") and (.feature | startswith("module_")) then
{
"id": .id,
"description": .description,
"command": ("see_menu " + .feature),
"options": ("help " + .options + " status"),
"status": .status,
"status": .status,
"helpers": .helpers,
"condition": .condition,
"author": .author
}
else empty
end
]'
"condition": .condition,
"author": .author
}
else empty
end
]'
}



interface_json_data() {
# Test Function

# uncomment to set the data to a file
#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"


Expand Down

0 comments on commit be10d7b

Please sign in to comment.