mirror of
https://github.com/garrytan/gstack.git
synced 2026-09-09 14:38:59 +02:00
feat(gstack-config): has <key> — key-presence provenance through STATE_DIR resolution
`get` returns the DEFAULTS value for absent keys, so callers that need to know whether the USER decided something (vs inherited a default) had no correct primitive — setup's consent logic was about to grep a hardcoded ~/.gstack/config.yaml, which misclassifies under GSTACK_STATE_ROOT / GSTACK_HOME / GSTACK_STATE_DIR overrides. `has` exits 0 iff the key is literally present in the resolved config file, with the same C-locale key validation as get/set. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
ac69e1d2b2
commit
cec156c9f1
@@ -3,6 +3,9 @@
|
||||
#
|
||||
# Usage:
|
||||
# gstack-config get <key> — read a config value (falls back to DEFAULTS)
|
||||
# gstack-config has <key> — exit 0 iff the key is literally present in the
|
||||
# config file (get returns DEFAULTS for absent keys,
|
||||
# so callers that need provenance use this instead)
|
||||
# gstack-config set <key> <value> — write a config value
|
||||
# gstack-config list — show all config (values + defaults)
|
||||
# gstack-config defaults — show just the defaults table
|
||||
@@ -301,6 +304,14 @@ case "${1:-}" in
|
||||
fi
|
||||
printf '%s' "$VALUE"
|
||||
;;
|
||||
has)
|
||||
KEY="${2:?Usage: gstack-config has <key>}"
|
||||
if ! printf '%s' "$KEY" | LC_ALL=C grep -qE '^[a-zA-Z0-9_]+(@[a-zA-Z0-9]+)?$'; then
|
||||
echo "Error: key must contain only alphanumeric characters, underscores, and an optional @<endpoint-id> suffix" >&2
|
||||
exit 1
|
||||
fi
|
||||
grep -qE "^${KEY}:" "$CONFIG_FILE" 2>/dev/null
|
||||
;;
|
||||
set)
|
||||
KEY="${2:?Usage: gstack-config set <key> <value>}"
|
||||
VALUE="${3:?Usage: gstack-config set <key> <value>}"
|
||||
|
||||
Reference in New Issue
Block a user