2024-03-04 23:02:50 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2024-03-08 22:40:38 +03:00
|
|
|
self=$(/usr/bin/env realpath ${0})
|
2024-03-04 23:02:50 +03:00
|
|
|
cd ${self%/*}
|
|
|
|
|
2024-03-08 22:40:38 +03:00
|
|
|
export BASH_PATH="../module/common/bash"
|
|
|
|
|
|
|
|
# Source modules.
|
|
|
|
for file in ${BASH_PATH}/module/*.sh; do
|
|
|
|
source "${file}"
|
|
|
|
done
|
|
|
|
|
2024-03-04 23:02:50 +03:00
|
|
|
IFS=$'\n'
|
|
|
|
file="Bash.md"
|
|
|
|
|
|
|
|
# Print title.
|
|
|
|
echo "# Bash reference file." > "${file}"
|
|
|
|
echo >> "${file}"
|
|
|
|
|
|
|
|
# Print help info.
|
|
|
|
echo "To get help with usage info run:" >> "${file}"
|
|
|
|
echo >> "${file}"
|
|
|
|
echo '```text' >> "${file}"
|
|
|
|
echo '$ help <COMMAND>' >> "${file}"
|
|
|
|
echo >> "${file}"
|
|
|
|
echo "or" >> "${file}"
|
|
|
|
echo >> "${file}"
|
|
|
|
echo '$ h <COMMAND>' >> "${file}"
|
|
|
|
echo '```' >> "${file}"
|
|
|
|
echo >> "${file}"
|
|
|
|
|
|
|
|
# Fill with data.
|
|
|
|
for module in $(find_module); do
|
2024-03-08 22:48:02 +03:00
|
|
|
functions=($(find_function ${module} ))
|
|
|
|
|
2024-03-04 23:02:50 +03:00
|
|
|
# Skip if no functions.
|
2024-03-08 22:48:02 +03:00
|
|
|
[[ "$(printf "%s\n" ${functions[@]} | /usr/bin/env grep -v ^_)" = "" ]] && continue
|
2024-03-04 23:02:50 +03:00
|
|
|
|
|
|
|
# Print module title.
|
|
|
|
echo "## ${module^}." >> "${file}"
|
|
|
|
echo >> "${file}"
|
|
|
|
|
|
|
|
# Print table title.
|
|
|
|
echo "Command|Description" >> "${file}"
|
|
|
|
echo "---|---" >> "${file}"
|
|
|
|
|
2024-03-08 22:48:02 +03:00
|
|
|
for fun in ${functions[@]}; do
|
2024-03-04 23:02:50 +03:00
|
|
|
# Skip private functions.
|
|
|
|
[[ "${fun}" =~ ^_.* ]] && continue
|
|
|
|
|
|
|
|
# Parse help info.
|
2024-03-08 22:40:38 +03:00
|
|
|
desc="$(help ${fun} | /usr/bin/env grep -v Usage\: | /usr/bin/env tr '\n' ' ')"
|
|
|
|
usage="$(help ${fun} | /usr/bin/env grep Usage\: | /usr/bin/env sed -e s\/Usage\:\ \/\/)"
|
2024-03-04 23:02:50 +03:00
|
|
|
|
|
|
|
# Use function name if no usage info available.
|
|
|
|
[[ "${usage}" = "" ]] && usage="${fun}"
|
|
|
|
|
|
|
|
# Write to file.
|
|
|
|
[[ "${desc}" != "" ]] && echo "\`${usage}\`|${desc}" >> "${file}"
|
|
|
|
done
|
|
|
|
|
|
|
|
echo >> "${file}"
|
|
|
|
done
|