mirror of
https://github.com/notwa/rc
synced 2025-02-05 07:43:22 -08:00
support self-documentation
This commit is contained in:
parent
1cc9a75b29
commit
7402cee176
1 changed files with 11 additions and 9 deletions
20
sh/document
20
sh/document
|
@ -9,18 +9,19 @@
|
||||||
# https://github.com/dylanaraps/pure-sh-bible
|
# https://github.com/dylanaraps/pure-sh-bible
|
||||||
|
|
||||||
document2() {
|
document2() {
|
||||||
|
local c=0 # line count
|
||||||
|
local d="#""#""#" # marker/delimiter, written this way to avoid self-matching
|
||||||
|
# NOTE: since the marker corresponds to a <h3> in markdown, it's used there too.
|
||||||
|
local e="${f#sh/}" # function name to expect
|
||||||
local f="$1" # file
|
local f="$1" # file
|
||||||
local c=0 # (line) count
|
[ "$f" != "$e" ] || e="" # only expect function names for stuff in sh/
|
||||||
local e="${f#sh/}" # expecting (function name matches filename)
|
|
||||||
[ "$f" != "$e" ] || e=""
|
|
||||||
[ "$e" != document ] || return 0 # doesn't play nicely yet, so skip it
|
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
: $((c+=1))
|
: $((c+=1))
|
||||||
# we only care about lines with our docstring marker in them:
|
# we only care about lines with our docstring marker in them:
|
||||||
case "$line" in *'###'*) :;; *) continue;; esac
|
case "$line" in *"$d"*) :;; *) continue;; esac
|
||||||
|
|
||||||
# split by the marker:
|
# split by the marker:
|
||||||
local code="${line%%###*}" docs="${line#*###}"
|
local code="${line%%$d*}" docs="${line#*$d}"
|
||||||
code="${code#${code%%[! ]*}}" # ltrim
|
code="${code#${code%%[! ]*}}" # ltrim
|
||||||
docs="${docs#${docs%%[! ]*}}" # ltrim
|
docs="${docs#${docs%%[! ]*}}" # ltrim
|
||||||
|
|
||||||
|
@ -68,11 +69,11 @@ document2() {
|
||||||
[ "$f" != "${f#sh/}" ] && url="/sh/${f#sh/}#L$c" || url="/home/${f#.}#L$c"
|
[ "$f" != "${f#sh/}" ] && url="/sh/${f#sh/}#L$c" || url="/home/${f#.}#L$c"
|
||||||
if [ "$n" = "$e" ]; then
|
if [ "$n" = "$e" ]; then
|
||||||
# function name matches the filename.
|
# function name matches the filename.
|
||||||
printf '\n### [%s](%s)\n\n' "$n" "$url" >> rc/README.md~ || return 5
|
printf '\n%s [%s](%s)\n\n' "$d" "$n" "$url" >> rc/README.md~ || return 5
|
||||||
else
|
else
|
||||||
# this file contains some other function, so include the filename.
|
# this file contains some other function, so include the filename.
|
||||||
printf '\n### [%s](%s)\n\n' "$n (${f#.})" "$url" >> rc/README.md~ || return 5
|
printf '\n%s [%s](%s)\n\n' "$d" "$n (${f#.})" "$url" >> rc/README.md~ || return 5
|
||||||
#printf '\n### %s\n\n* defined in [%s](%s)\n\n' "$n" "$f" "$url" >> rc/README.md~ || return 5
|
#printf '\n%s %s\n\n* defined in [%s](%s)\n\n' "%d" "$n" "$f" "$url" >> rc/README.md~ || return 5
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -122,6 +123,7 @@ document1() {
|
||||||
|
|
||||||
document() { ### @-
|
document() { ### @-
|
||||||
### generate a markdown file out of docstrings in shell scripts.
|
### generate a markdown file out of docstrings in shell scripts.
|
||||||
|
###
|
||||||
### **TODO:** describe. i have a rough outline written in my scrap file.
|
### **TODO:** describe. i have a rough outline written in my scrap file.
|
||||||
|
|
||||||
document1 "$@"
|
document1 "$@"
|
||||||
|
|
Loading…
Add table
Reference in a new issue