MCPcopy Create free account
hub / github.com/algolia/cli / Print

Method Print

pkg/printers/jsonpath.go:31–43  ·  view source on GitHub ↗

Print formats the interface with the JSONPath Template.

(ios *iostreams.IOStreams, data interface{})

Source from the content-addressed store, hash-verified

29
30// Print formats the interface with the JSONPath Template.
31func (j *JSONPathPrinter) Print(ios *iostreams.IOStreams, data interface{}) error {
32 err := j.JSONPath.Execute(ios.Out, data)
33 if err == nil {
34 _, _ = ios.Out.Write([]byte("\n"))
35 } else {
36 buf := bytes.NewBuffer(nil)
37 fmt.Fprintf(buf, "Error executing template: %v. Printing more information for debugging the template:\n", err)
38 fmt.Fprintf(buf, "\ttemplate was:\n\t\t%v\n", j.rawTemplate)
39 fmt.Fprintf(buf, "\tobject given to jsonpath engine was:\n\t\t%#v\n\n", data)
40 return fmt.Errorf("error executing jsonpath %q: %v", j.rawTemplate, buf.String())
41 }
42 return nil
43}
44
45// AllowMissingKeys tells the template engine if missing keys are allowed.
46func (j *JSONPathPrinter) AllowMissingKeys(allow bool) {

Callers

nothing calls this directly

Calls 2

ErrorfMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected