build-cli-usage.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. usage=$(cargo -q run -p solana-cli -- -C ~/.foo --help | sed -e 's|'"$HOME"'|~|g' -e 's/[[:space:]]\+$//')
  25. section() {
  26. declare mark=${2:-"###"}
  27. declare section=$1
  28. read -r name rest <<<"$section"
  29. printf '%s %s
  30. ' "$mark" "$name"
  31. printf '```text
  32. %s
  33. ```
  34. ' "$section"
  35. }
  36. section "$usage" >> "$out"
  37. usage=$(sed -e '/^ \{5,\}/d' <<<"$usage")
  38. in_subcommands=0
  39. while read -r subcommand rest; do
  40. [[ $subcommand == "SUBCOMMANDS:" ]] && in_subcommands=1 && continue
  41. if ((in_subcommands)); then
  42. section "$(cargo -q run -p solana-cli -- help "$subcommand" | sed -e 's|'"$HOME"'|~|g' -e 's/[[:space:]]\+$//')" "###" >> "$out"
  43. fi
  44. done <<<"$usage">>"$out"