feat: add --json flag to validate/inspect CLI and switch tests to exhaustive variants

Add `--json` CLI flag for both `validate` and `inspect` subcommands, enabling raw JSON output via `r.toJson().pretty()` instead of formatted report. Update Makefile test targets to use `test_json_exhaustive`, `test_yaml_exhaustive`, and `test_toml_exhaustive` test files. Extend `.gitignore` to exclude the new exhaustive test binaries. Revise README with version header, table of contents, and restructured documentation.
This commit is contained in:
retoor 2026-07-08 08:19:01 +00:00
parent 72a7b661db
commit 330adff37c
4 changed files with 1034 additions and 215 deletions

5
.gitignore vendored
View File

@ -1,3 +1,8 @@
tests/test_json_exhaustive
tests/test_toml_exhaustive
tests/test_yaml_exhaustive
# ── Nim ──────────────────────────────────────────────────────────────────
nimcache/
nimblecache/

View File

@ -52,13 +52,13 @@ test-jinja:
$(NIMC) -r $(TEST_DIR)/test_jinja.nim
test-json:
$(NIMC) -r $(TEST_DIR)/test_json.nim
$(NIMC) -r $(TEST_DIR)/test_json_exhaustive.nim
test-yaml:
$(NIMC) -r $(TEST_DIR)/test_yaml.nim
$(NIMC) -r $(TEST_DIR)/test_yaml_exhaustive.nim
test-toml:
$(NIMC) -r $(TEST_DIR)/test_toml.nim
$(NIMC) -r $(TEST_DIR)/test_toml_exhaustive.nim
test-mixed:
$(NIMC) -r $(TEST_DIR)/test_mixed.nim

1222
README.md

File diff suppressed because it is too large Load Diff

View File

@ -315,6 +315,7 @@ when isMainModule:
of "validate", "val":
var filePath, source, flavor = ""
var debugMode = false
var jsonOut = false
var i = 1
while i < args.len:
let a = args[i]
@ -322,6 +323,7 @@ when isMainModule:
elif a.startsWith("--source="): source = a[9..^1]
elif a.startsWith("--flavor="): flavor = a[9..^1]
elif a == "--debug": debugMode = true
elif a == "--json": jsonOut = true
i += 1
var opts = newValidationOptions()
@ -333,20 +335,27 @@ when isMainModule:
except: discard
var r: ValidationResult
var src: string = ""
if filePath.len > 0:
r = validateFile(filePath, fl, opts)
if fileExists(filePath): src = readFile(filePath)
elif source.len > 0:
src = source
r = validateSource(source, fl, opts, "stdin")
else:
# Read from stdin
let input = readAll(stdin).strip()
r = validateSource(input, fl, opts, "stdin")
src = readAll(stdin).strip()
r = validateSource(src, fl, opts, "stdin")
echo formatReport(r, r.moduleInfo.toJson().pretty())
if jsonOut:
echo r.toJson().pretty()
else:
echo formatReport(r, src)
of "inspect", "ins":
var filePath, source, flavor = ""
var debugMode = false
var jsonOut = false
var i = 1
while i < args.len:
let a = args[i]
@ -354,6 +363,7 @@ when isMainModule:
elif a.startsWith("--source="): source = a[9..^1]
elif a.startsWith("--flavor="): flavor = a[9..^1]
elif a == "--debug": debugMode = true
elif a == "--json": jsonOut = true
i += 1
var opts = newValidationOptions()