build-cli-usage.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env bash
  2. set -e
  3. cd "$(dirname "$0")"
  4. # shellcheck source=ci/env.sh
  5. source ../ci/env.sh
  6. # Get current channel
  7. eval "$(../ci/channel-info.sh)"
  8. # set the output file' location
  9. out=${1:-src/cli/usage.md}
  10. # load the usage file's header
  11. cat src/cli/.usage.md.header > "$out"
  12. # Skip generating the detailed usage doc for non deployment commits of the docs
  13. if [[ -n $CI ]]; then
  14. if [[ $CI_BRANCH != $EDGE_CHANNEL* ]] && [[ $CI_BRANCH != $BETA_CHANNEL* ]] && [[ $CI_BRANCH != $STABLE_CHANNEL* ]]; then
  15. echo "**NOTE:** The usage doc is only auto-generated during full production deployments of the docs"
  16. echo "**NOTE:** This usage doc is auto-generated during deployments" >> "$out"
  17. exit
  18. fi
  19. fi
  20. echo 'Building the solana cli from source...'
  21. # shellcheck source=ci/rust-version.sh
  22. source ../ci/rust-version.sh stable
  23. : "${rust_stable:=}" # Pacify shellcheck
  24. # pre-build with output enabled to appease Travis CI's hang check
  25. cargo build -p solana-cli
  26. usage=$(cargo -q run -p solana-cli -- -C ~/.foo --help | sed -e 's|'"$HOME"'|~|g' -e 's/[[:space:]]\+$//')
  27. section() {
  28. declare mark=${2:-"###"}
  29. declare section=$1
  30. read -r name rest <<<"$section"
  31. printf '%s %s
  32. ' "$mark" "$name"
  33. printf '```text
  34. %s
  35. ```
  36. ' "$section"
  37. }
  38. section "$usage" >> "$out"
  39. usage=$(sed -e '/^ \{5,\}/d' <<<"$usage")
  40. in_subcommands=0
  41. while read -r subcommand rest; do
  42. [[ $subcommand == "SUBCOMMANDS:" ]] && in_subcommands=1 && continue
  43. if ((in_subcommands)); then
  44. section "$(cargo -q run -p solana-cli -- help "$subcommand" | sed -e 's|'"$HOME"'|~|g' -e 's/[[:space:]]\+$//')" "####" >> "$out"
  45. fi
  46. done <<<"$usage">>"$out"