-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-readme
More file actions
executable file
·66 lines (56 loc) · 1.75 KB
/
Copy pathupdate-readme
File metadata and controls
executable file
·66 lines (56 loc) · 1.75 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env bash
set -euo pipefail
# export NO_COLOR=1
# export CLICOLOR=0
# export LC_ALL=C
README="readme.md"
BIN="./target/release/nhl"
DOCBIN="nhl"
render() {
local cmd_display="$1"
shift
local out
out="$(
NO_COLOR=1 CLICOLOR=0 CLICOLOR_FORCE=0 FORCE_COLOR=0 TERM=dumb LC_ALL=C \
"$@" 2>&1 | perl -pe 's/\e\[[0-9;]*[[:alpha:]]//g' || true
)"
cat <<EOF
\`\`\`text
$ ${cmd_display}
${out}
\`\`\`
EOF
}
replace_block() {
local name="$1"
local content="$2"
BLOCK_NAME="$name" BLOCK_CONTENT="$content" perl -0777 -i -pe '
my $name = $ENV{"BLOCK_NAME"};
my $content = $ENV{"BLOCK_CONTENT"};
s/(<!--\s*BEGIN:\Q$name\E\s*-->)(.*?)(<!--\s*END:\Q$name\E\s*-->)/$1\n\n$content\n\n$3/sg
or die "Could not find markers for $name\n";
' "$README"
}
# Each entry: block_name<TAB>display_string<TAB>command... (split by a delimiter)
# We’ll use | as a delimiter so args with spaces are manageable if you quote carefully.
BLOCKS=(
$'version|'"$DOCBIN"' -V|'"$BIN"'|-V'
$'help|'"$DOCBIN"' -h|'"$BIN"'|-h'
$'vanilla|'"$DOCBIN"' |'"$BIN"'|'
$'division|'"$DOCBIN"' -d|'"$BIN"'|-d'
$'conference|'"$DOCBIN"' -c|'"$BIN"'|-c'
$'full|'"$DOCBIN"' -f|'"$BIN"'|-f'
$'last10|'"$DOCBIN"' --l10|'"$BIN"'|--l10'
$'schedule|'"$DOCBIN"' -s|'"$BIN"'|-s'
$'teamschedule|'"$DOCBIN"' -s -t MTL|'"$BIN"'|-s|-t|MTL'
$'playoffs|'"$DOCBIN"' -p|'"$BIN"'|-p'
)
for entry in "${BLOCKS[@]}"; do
IFS='|' read -r block display first rest <<<"$entry" || true
# Re-split the command portion safely:
IFS='|' read -r -a argv <<<"${entry#*|*|}" # everything after first two fields
# argv now looks like: ("./target/release/mycli" "--help") etc.
content="$(render "$display" "${argv[@]}")"
replace_block "$block" "$content"
done
echo "Updated $README"