mirror of
https://github.com/garrytan/gstack.git
synced 2026-09-20 03:42:24 +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:
|
# Usage:
|
||||||
# gstack-config get <key> — read a config value (falls back to DEFAULTS)
|
# 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 set <key> <value> — write a config value
|
||||||
# gstack-config list — show all config (values + defaults)
|
# gstack-config list — show all config (values + defaults)
|
||||||
# gstack-config defaults — show just the defaults table
|
# gstack-config defaults — show just the defaults table
|
||||||
@@ -301,6 +304,14 @@ case "${1:-}" in
|
|||||||
fi
|
fi
|
||||||
printf '%s' "$VALUE"
|
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)
|
set)
|
||||||
KEY="${2:?Usage: gstack-config set <key> <value>}"
|
KEY="${2:?Usage: gstack-config set <key> <value>}"
|
||||||
VALUE="${3:?Usage: gstack-config set <key> <value>}"
|
VALUE="${3:?Usage: gstack-config set <key> <value>}"
|
||||||
|
|||||||
Reference in New Issue
Block a user