forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-cli-usage.sh
executable file
·45 lines (32 loc) · 1.01 KB
/
build-cli-usage.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
#!/usr/bin/env bash
set -e
cd "$(dirname "$0")"
cargo=../cargo
# shellcheck source=ci/rust-version.sh
source ../ci/rust-version.sh stable
: "${rust_stable:=}" # Pacify shellcheck
# pre-build with output enabled to appease Travis CI's hang check
"$cargo" build -p solana-cli
usage=$("$cargo" stable -q run -p solana-cli -- -C ~/.foo --help | sed -e 's|'"$HOME"'|~|g' -e 's/[[:space:]]\+$//')
out=${1:-src/cli/usage.md}
cat src/cli/.usage.md.header > "$out"
section() {
declare mark=${2:-"###"}
declare section=$1
read -r name rest <<<"$section"
printf '%s %s
' "$mark" "$name"
printf '```text
%s
```
' "$section"
}
section "$usage" >> "$out"
usage=$(sed -e '/^ \{5,\}/d' <<<"$usage")
in_subcommands=0
while read -r subcommand rest; do
[[ $subcommand == "SUBCOMMANDS:" ]] && in_subcommands=1 && continue
if ((in_subcommands)); then
section "$("$cargo" stable -q run -p solana-cli -- help "$subcommand" | sed -e 's|'"$HOME"'|~|g' -e 's/[[:space:]]\+$//')" "####" >> "$out"
fi
done <<<"$usage">>"$out"