This repository has been archived by the owner on Apr 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbashdoc
85 lines (67 loc) · 1.73 KB
/
bashdoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
### bashdoc [ "-"SECTION ] FILES ... Usage:help
#
# Provide the files you want to print the internal documentation for.
#
# By default, prints the "bbuild" documentation sections.
#
# To print just the `api` sections, call
#
# bashdoc -api ...
#
# To list just available modules, simply run `bashdoc` on its own
#
###/doc
#%include std/autohelp.sh
#%include std/out.sh
#%include std/searchpaths.sh
#%include std/runmain.sh
list_modules() {
local thepath f
out:info "Available modules: "
while read thepath; do
out:warn "Checking $thepath"
while read f; do
if [[ -f "$thepath/$f" ]]; then
echo "$f"
fi
done < <(ls "$thepath") | column
done < <(echo "$BBPATH"|sed 's/:/\n/g')
}
main() {
autohelp:check "$@"
if [[ -z "$*" ]]; then
list_modules
exit 0
fi
# ====================================================================
# Get the section, if specified.
SECTION='bbuild'
if [[ "${1:0:1}" = "-" ]]; then
SECTION="${1:1}"
shift
fi
out:info "Seeking section [$SECTION] on all files."
print_from "$@"
}
print_from() {
# =================
# Process files
for file in "$@"; do
if [[ ! -f "$file" ]]; then
fullpath="$(searchpaths:file_from "$BBPATH" "$file")"
if [[ -n "$fullpath" ]]; then
file="$fullpath"
fi
fi
if [[ ! -f "$file" ]]; then
out:warn "No such file [$file]"
continue
fi
egrep '^##bash-libs:' "$file"
# Also print the tags for info
egrep '^#%bbtags' "$file"
autohelp:print "$SECTION" "$file"
done
}
runmain bashdoc main "$@"