MCPcopy
hub / github.com/homeport/dyff / generateDiffSyntaxDiffOutput

Method generateDiffSyntaxDiffOutput

pkg/dyff/output_diff_syntax.go:60–98  ·  view source on GitHub ↗

generatedyffSyntaxDiffOutput creates a human readable report of the provided diff and writes this into the given bytes buffer. There is an optional flag to indicate whether the document index (which documents of the input file) should be included in the report of the path of the difference.

(output stringWriter, diff Diff, useGoPatchPaths bool, showPathRoot bool)

Source from the content-addressed store, hash-verified

58
59// generatedyffSyntaxDiffOutput creates a human readable report of the provided diff and writes this into the given bytes buffer. There is an optional flag to indicate whether the document index (which documents of the input file) should be included in the report of the path of the difference.
60func (report *DiffSyntaxReport) generateDiffSyntaxDiffOutput(output stringWriter, diff Diff, useGoPatchPaths bool, showPathRoot bool) error {
61 _, _ = output.WriteString(fmt.Sprintf("\n%s ", report.PathPrefix))
62 if useGoPatchPaths {
63 _, _ = output.WriteString(styledGoPatchPath(diff.Path))
64
65 } else {
66 _, _ = output.WriteString(styledDotStylePath(diff.Path))
67 }
68 // Only @@ also needs a postfix
69 if report.PathPrefix == "@@" {
70 _, _ = output.WriteString(" @@")
71 }
72 _, _ = output.WriteString("\n")
73
74 // Write the root description onto its own line
75 if diff.Path != nil && showPathRoot {
76 _, _ = output.WriteString(fmt.Sprintf("%s %s\n", report.RootDescriptionPrefix, diff.Path.RootDescription()))
77 }
78
79 blocks := make([]string, len(diff.Details))
80 for i, detail := range diff.Details {
81 generatedOutput, err := report.generateDiffSyntaxDetailOutput(detail)
82 if err != nil {
83 return err
84 }
85
86 blocks[i] = generatedOutput
87 }
88
89 // For the use case in which only a path-less diff is suppose to be printed,
90 // omit the indent in this case since there is only one element to show
91 indent := 0
92 if diff.Path != nil && len(diff.Path.PathElements) == 0 {
93 indent = 0
94 }
95
96 report.writeTextBlocks(output, indent, blocks...)
97 return nil
98}
99
100// generatedyffSyntaxDetailOutput only serves as a dispatcher to call the correct sub function for the respective type of change
101func (report *DiffSyntaxReport) generateDiffSyntaxDetailOutput(detail Detail) (string, error) {

Callers 1

WriteReportMethod · 0.95

Calls 5

styledGoPatchPathFunction · 0.85
styledDotStylePathFunction · 0.85
WriteStringMethod · 0.80
writeTextBlocksMethod · 0.80

Tested by

no test coverage detected