2019-09-29 21:18:15 -07:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
|
|
|
|
cd "$(dirname "$0")"
|
2021-01-29 09:48:25 -08:00
|
|
|
cargo=../cargo
|
2019-09-29 21:18:15 -07:00
|
|
|
|
2020-07-10 22:11:07 -07:00
|
|
|
# shellcheck source=ci/rust-version.sh
|
|
|
|
source ../ci/rust-version.sh stable
|
|
|
|
|
2020-04-15 17:42:18 -07:00
|
|
|
: "${rust_stable:=}" # Pacify shellcheck
|
|
|
|
|
2022-02-02 00:04:27 -08:00
|
|
|
# pre-build with output enabled to appease Travis CI's hang check
|
|
|
|
"$cargo" build -p solana-cli
|
|
|
|
|
2020-10-12 20:19:41 -07:00
|
|
|
usage=$("$cargo" stable -q run -p solana-cli -- -C ~/.foo --help | sed -e 's|'"$HOME"'|~|g' -e 's/[[:space:]]\+$//')
|
2019-09-29 21:18:15 -07:00
|
|
|
|
2020-01-23 20:21:43 -08:00
|
|
|
out=${1:-src/cli/usage.md}
|
2019-09-29 21:18:15 -07:00
|
|
|
|
2020-01-23 20:21:43 -08:00
|
|
|
cat src/cli/.usage.md.header > "$out"
|
2019-09-29 21:18:15 -07:00
|
|
|
|
|
|
|
section() {
|
|
|
|
declare mark=${2:-"###"}
|
|
|
|
declare section=$1
|
|
|
|
read -r name rest <<<"$section"
|
|
|
|
|
|
|
|
printf '%s %s
|
|
|
|
' "$mark" "$name"
|
|
|
|
printf '```text
|
|
|
|
%s
|
|
|
|
```
|
|
|
|
|
|
|
|
' "$section"
|
|
|
|
}
|
|
|
|
|
|
|
|
section "$usage" >> "$out"
|
|
|
|
|
2020-03-18 22:24:42 -07:00
|
|
|
usage=$(sed -e '/^ \{5,\}/d' <<<"$usage")
|
|
|
|
|
2019-09-29 21:18:15 -07:00
|
|
|
in_subcommands=0
|
|
|
|
while read -r subcommand rest; do
|
|
|
|
[[ $subcommand == "SUBCOMMANDS:" ]] && in_subcommands=1 && continue
|
|
|
|
if ((in_subcommands)); then
|
2020-10-12 20:19:41 -07:00
|
|
|
section "$("$cargo" stable -q run -p solana-cli -- help "$subcommand" | sed -e 's|'"$HOME"'|~|g' -e 's/[[:space:]]\+$//')" "####" >> "$out"
|
2019-09-29 21:18:15 -07:00
|
|
|
fi
|
|
|
|
done <<<"$usage">>"$out"
|