tools: fix fbq-add-source.sh failing to list sources with inline yaml comments

yq stops mid-array when it encounters inline comments like
'# grant per-user only'. Strip comments via sed before piping
to yq in list_sources, source_exists, and before in-place edits.

https://claude.ai/code/session_014CCYqVwW6d6f5dw1qRokYt
This commit is contained in:
Claude
2026-06-08 12:37:57 +00:00
parent 5af33a9ebb
commit 6030c8b06d
+8 -2
View File
@@ -107,13 +107,16 @@ backup() {
# ── Check if a source path already exists in config ──────────────────────────
source_exists() {
local config="$1" path="$2"
yq e '.server.sources[].path' "$config" 2>/dev/null | grep -qxF "$path"
sed 's/[[:space:]]*#.*$//' "$config" \
| yq e '.server.sources[].path' - 2>/dev/null \
| grep -qxF "$path"
}
# ── List existing sources ─────────────────────────────────────────────────────
list_sources() {
local config="$1"
yq e '.server.sources[] | .path' "$config" 2>/dev/null
# Strip inline comments before parsing — yq can mishandle them mid-array
sed 's/[[:space:]]*#.*$//' "$config" | yq e '.server.sources[] | .path' - 2>/dev/null
}
# ── Restart the container ─────────────────────────────────────────────────────
@@ -179,6 +182,9 @@ cmd_add() {
[[ "${read_only_bool_raw,,}" == "y" ]] && read_only_bool="true"
backup "$config"
# Strip inline comments first so yq edits cleanly
local tmp; tmp=$(mktemp)
sed 's/[[:space:]]*#.*$//' "$config" > "$tmp" && mv "$tmp" "$config"
yq e -i ".server.sources += [{
\"path\": \"${container_path}\",
\"name\": \"${source_name}\",