feat(jsontypes): wire jsonpaths CLI to use RawPaths→Coalesce pipeline

In anonymous mode (-anonymous), jsonpaths now uses the deterministic
pipeline (RawPaths → Coalesce → Generate) instead of the legacy
analyzer. Interactive mode still uses the old analyzer with resolver.
This commit is contained in:
AJ ONeal 2026-03-08 00:29:33 -07:00
parent f2045c7831
commit 4dc269f0c2
No known key found for this signature in database

View File

@ -166,9 +166,14 @@ func main() {
os.Exit(1) os.Exit(1)
} }
var resolver jsontypes.Resolver var formatted []string
var pr *prompter var pr *prompter
if !*anonymous { if *anonymous {
// Pipeline mode: RawPaths → Coalesce → Generate (deterministic, no prompts).
raw := jsontypes.RawPaths(data)
formatted = jsontypes.Coalesce(raw)
} else {
// Interactive mode: use legacy analyzer with resolver.
pr, err = newPrompter(inputIsStdin) pr, err = newPrompter(inputIsStdin)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err) fmt.Fprintf(os.Stderr, "error: %v\n", err)
@ -178,15 +183,14 @@ func main() {
if baseName != "" { if baseName != "" {
pr.loadAnswers(baseName + ".answers") pr.loadAnswers(baseName + ".answers")
} }
resolver = newCLIResolver(pr) resolver := newCLIResolver(pr)
}
a := jsontypes.New(jsontypes.AnalyzerConfig{ a := jsontypes.New(jsontypes.AnalyzerConfig{
Resolver: resolver, Resolver: resolver,
AskTypes: *askTypes, AskTypes: *askTypes,
}) })
rawPaths := a.Analyze(".", data) rawPaths := a.Analyze(".", data)
formatted := jsontypes.FormatPaths(rawPaths) formatted = jsontypes.FormatPaths(rawPaths)
}
out, err := jsontypes.Generate(outFormat, formatted) out, err := jsontypes.Generate(outFormat, formatted)
if err != nil { if err != nil {
@ -202,7 +206,7 @@ func main() {
fmt.Fprintf(os.Stderr, "warning: could not write %s: %v\n", pathsFile, err) fmt.Fprintf(os.Stderr, "warning: could not write %s: %v\n", pathsFile, err)
} }
if !*anonymous && pr != nil { if pr != nil {
answersFile := baseName + ".answers" answersFile := baseName + ".answers"
if err := pr.saveAnswers(answersFile); err != nil { if err := pr.saveAnswers(answersFile); err != nil {
fmt.Fprintf(os.Stderr, "warning: could not write %s: %v\n", answersFile, err) fmt.Fprintf(os.Stderr, "warning: could not write %s: %v\n", answersFile, err)