#!/usr/bin/env bash

cat >mise.toml <<'TOML'
[vars]
greeting = "hello"
secret = { value = "hunter2", redact = true }
TOML

assert "mise vars --json | jq -r .greeting" "hello"
assert "mise vars ls --json | jq -r .greeting" "hello"
assert "mise vars -J | jq -r .secret" "[redacted]"
assert "mise vars --json-extended | jq -r .greeting.value" "hello"
assert_contains "mise vars --json-extended | jq -r .greeting.source" "mise.toml"
assert_fail "mise vars --json --no-header"

# JSON keeps the full source path, and works before the subcommand
assert "mise vars --json ls | jq -r .greeting" "hello"
assert "mise vars --json-extended ls | jq -r .greeting.source" "$PWD/mise.toml"

# Named reads print a bare value, so JSON flags are rejected rather than ignored
assert_fail_contains "mise vars --json greeting" "cannot be used with NAME"

# Flags given before the subcommand still conflict with the ones after it
assert_fail_contains "mise vars --no-header ls --json" "--no-header cannot be combined"
assert_fail_contains "mise vars --json ls --json-extended" "--json cannot be combined"
