-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-readme.md.sh
171 lines (146 loc) · 3.3 KB
/
generate-readme.md.sh
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/bin/bash
get_options_output () {
local command=$1
gather=false
$command | while read line; do
if [ -z "$line" ]; then
continue
fi
if echo "$line" | grep -q "\s*Examples:\s*$"; then
gather=false;
fi
if [ $gather = "true" ]; then
if ! echo $line | grep -q "^help"; then
echo $line
fi
fi
if echo "$line" | grep -q "\s*Options:\s*$"; then
if [ $gather = "false" ]; then
gather=true
fi
fi
done
}
get_examples_output () {
local command=$1
gather=false
$command | while read line; do
if [ $gather = "true" ]; then
if ! echo $line | grep -q "^help"; then
echo $line
fi
fi
if echo "$line" | grep -q "\s*Examples:\s*$"; then
if [ $gather = "false" ]; then
gather=true
fi
fi
done
}
get_command_output () {
local command=$1
gather=false
$command | while read line; do
if [ -z "$line" ]; then
continue
fi
if echo "$line" | grep -q "\s*Options:\s*$"; then
gather=false;
fi
if [ $gather = "true" ]; then
if ! echo $line | grep -q "^help"; then
echo $line
fi
fi
if echo "$line" | grep -q "\s*Commands:\s*$"; then
if [ $gather = "false" ]; then
gather=true
fi
fi
done
}
title(){
local output="$1"
echo "# $output"
echo "======================================================================"
}
level1title(){
local output="$1"
echo "## $output"
echo
}
level2title(){
local output="$1"
echo "### $output"
echo
}
level4title(){
local output="$1"
echo "##### $output"
echo
}
level5title(){
local output="$1"
echo "###### $output"
echo
}
level3title(){
local output="$1"
echo "#### $output"
echo
}
writeCode(){
local output="$1"
echo '```'
echo "$output"
echo '```'
}
getDoc(){
local doc="$1"
output="$(cat partials/$1)"
echo "$output"
}
title "CloudCoreo CLI"
echo
getDoc "INSTALL.md"
#echo
#getDoc "CONFIGURE.md"
echo
level1=$(get_command_output "./coreo.js --help")
level1title "Commands"
echo "The following is a list of commands that can be run with the CLI tool. This is auto-generated."
echo
opts="$(get_options_output "./coreo.js --help")"
level4title "Options"
writeCode "$opts"
echo
echo "The [CloudCoreo](http://www.cloudcoreo.com/) CLI uses git-style subcommands."
echo "For help, try:"
writeCode "coreo help <command>"
echo "or"
writeCode "coreo <command> help <subcommand>"
echo "$level1" | while read line; do
command=$(echo "$line" | awk '{print $1}')
desc=$(echo "$line" | awk '{first = $1; $1 = ""; print $0; }' | perl -pe 's{^\s(.*$)}{\1}g')
echo
level2title "coreo $command"
echo "$desc"
level3title "Options"
opts="$(get_options_output "./coreo.js help $command")"
writeCode "$opts"
level2=$(get_command_output "./coreo.js help $command")
level3title "Actions"
echo "$level2" | while read lineLev3; do
commandLev3=$(echo "$lineLev3" | awk '{print $1}')
descLev3=$(echo "$lineLev3" | awk '{$1=$2=""; print $0}')
level4title "Action: $commandLev3"
echo "$descLev3"
echo
opts="$(get_options_output "./coreo.js $command $commandLev3 --help")"
level5title "Options:"
writeCode "$opts"
exam="$(get_examples_output "./coreo.js $command $commandLev3 --help")"
level5title "Examples:"
writeCode "$exam"
done
done