Makefile : Add doc generation.

This commit is contained in:
Dmitry Voronin 2024-03-04 23:02:50 +03:00
parent 6de0dc0efa
commit f8d6b90c75
5 changed files with 67 additions and 52 deletions

View file

@ -1,3 +1,3 @@
for file in .config/linux/system/module/common/bash/module/*; do
for file in module/common/bash/module/*; do
source ${file}
done

View file

@ -16,6 +16,12 @@ Command|Description
---|---
`emulator [NAME]`|Start an Android emulator. Default name is `main`.
## App.
Command|Description
---|---
`steam_link`| Start steam in Steam Link mode.
## Archive.
Command|Description
@ -36,7 +42,6 @@ Command|Description
Command|Description
---|---
`ask <QUERY>`|Ask general AI.
`ask_code <QUERY>`|Ask code AI.
## Battery.
@ -288,6 +293,8 @@ Command|Description
`nix_shell [NAME]`|Spawn shell with specified nix environment. Uses flake.nix in current dir by default.
`nix_tmpshell <PACKAGES>`|Spawn nix-shell with specified packages.
`nix_live`| Build live image.
`nix_generations`| List nixos generations.
`nixdroid_switch`| Switch nix-on-droid.
## Notify.

54
.doc/Generate.sh Executable file
View file

@ -0,0 +1,54 @@
#!/usr/bin/env bash
self=$(realpath .)
cd ${self%/*}
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
# Skip if no functions.
[[ "$(find_function ${module} | grep -v ^_)" = "" ]] && continue
# Print module title.
echo "## ${module^}." >> "${file}"
echo >> "${file}"
# Print table title.
echo "Command|Description" >> "${file}"
echo "---|---" >> "${file}"
for fun in $(find_function ${module}); do
# Skip private functions.
[[ "${fun}" =~ ^_.* ]] && continue
# Parse help info.
desc="$(help ${fun} | grep -v Usage\: | tr '\n' ' ')"
usage="$(help ${fun} | grep Usage\: | sed -e s\/Usage\:\ \/\/)"
# Use function name if no usage info available.
[[ "${usage}" = "" ]] && usage="${fun}"
# Write to file.
[[ "${desc}" != "" ]] && echo "\`${usage}\`|${desc}" >> "${file}"
done
echo >> "${file}"
done

3
Makefile Normal file
View file

@ -0,0 +1,3 @@
.PHONY: doc
doc:
@.doc/Generate.sh

View file

@ -1,53 +1,4 @@
# Generate a markdown file with all the help info.
# Outputs to `~/.doc/Bash.md`.
# Outputs to `.doc/Bash.md`.
function doc_bash() {
local IFS=$'\n'
local file="${HOME}/.doc/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
# Skip if no functions.
[[ "$(find_function ${module} | grep -v ^_)" = "" ]] && continue
# Print module title.
echo "## ${module^}." >> "${file}"
echo >> "${file}"
# Print table title.
echo "Command|Description" >> "${file}"
echo "---|---" >> "${file}"
for fun in $(find_function ${module}); do
# Skip private functions.
[[ "${fun}" =~ ^_.* ]] && continue
# Parse help info.
local desc="$(help ${fun} | grep -v Usage\: | tr '\n' ' ')"
local usage="$(help ${fun} | grep Usage\: | sed -e s\/Usage\:\ \/\/)"
# Use function name if no usage info available.
[[ "${usage}" = "" ]] && usage="${fun}"
# Write to file.
[[ "${desc}" != "" ]] && echo "\`${usage}\`|${desc}" >> "${file}"
done
echo >> "${file}"
done
}