31 lines
694 B
Bash
31 lines
694 B
Bash
#!/usr/bin/env bash
|
|
# 自動補全與修正 docker-compose.yaml 行內註解內容
|
|
# 用法: bash scripts/fix_comments.sh <file>
|
|
|
|
set -euo pipefail
|
|
file="${1:-}"
|
|
if [ -z "$file" ]; then
|
|
echo "請指定要處理的檔案"
|
|
exit 1
|
|
fi
|
|
|
|
tmp_file="$(mktemp "${file}.tmp.XXXXXX")"
|
|
trap 'rm -f -- "$tmp_file"' EXIT
|
|
|
|
awk '
|
|
/^[[:space:]]*#/ { print; next }
|
|
/[[:space:]]+#/ {
|
|
match($0, /[[:space:]]+#/);
|
|
code=substr($0, 1, RSTART - 1);
|
|
comment=substr($0, RSTART + RLENGTH);
|
|
gsub(/^ +| +$/, "", comment);
|
|
if (length(comment)==0) comment="TODO: 補充說明";
|
|
print code " # " comment;
|
|
next;
|
|
}
|
|
{ print }
|
|
' "$file" > "$tmp_file"
|
|
|
|
mv -- "$tmp_file" "$file"
|
|
trap - EXIT
|