github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/util/fsm/gen/reports.sh (about) 1 #!/usr/bin/env bash 2 # 3 # reports.sh generates reports about the finite state machine. 4 # 5 # Usage: reports.sh <exported Transitions variable> <starting state name> 6 # 7 # Example: reports.sh TxnStateTransitions stateNoTxn 8 9 set -euo pipefail 10 11 # Determine the current package name. 12 full_pkg=$(go list) 13 base_pkg=$(basename "$full_pkg") 14 15 type="$1" 16 lower_type=$(echo "$1" | awk '{print tolower($0)}') 17 start_state="$2" 18 19 # Substitute variables in template .go file. 20 dir=$(mktemp -d) 21 write_reports=$dir/write_reports.go 22 write_reports_tmpl=$(dirname "$0")/write_reports.go.tmpl 23 sed -e "s~{tmpl-full-pkg}~$full_pkg~"\ 24 -e "s~{tmpl-base-pkg}~$base_pkg~"\ 25 -e "s~{tmpl-type}~$type~"\ 26 -e "s~{tmpl-start-state}~$start_state~"\ 27 "$write_reports_tmpl" > "$write_reports" 28 29 # Run .go file to generate reports. 30 diagram_file="$lower_type"_diagram.gv 31 report_file="$lower_type"_report.txt 32 go run "$write_reports" "$diagram_file" "$report_file" "$0 $*"