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:
parent
72a7b661db
commit
330adff37c
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,3 +1,8 @@
|
||||
|
||||
|
||||
tests/test_json_exhaustive
|
||||
tests/test_toml_exhaustive
|
||||
tests/test_yaml_exhaustive
|
||||
# ── Nim ──────────────────────────────────────────────────────────────────
|
||||
nimcache/
|
||||
nimblecache/
|
||||
|
||||
6
Makefile
6
Makefile
@ -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
|
||||
|
||||
@ -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()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user