Skip to content

Commit 83640dd

Browse files
committed
feat(printer)!: remove unsupported config options, add OmitScalarValues
1 parent ee92d33 commit 83640dd

File tree

2 files changed

+39
-33
lines changed

2 files changed

+39
-33
lines changed

printer/printer.go

+35-33
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,9 @@ type Config struct {
6767
// If set, the string to use for the start of each line.
6868
StartingIndent []byte
6969

70-
// Set to true if you like verbosity, I guess.
71-
// If false, strings will only have kind+type markings if they're typed.
72-
//
73-
// Not yet supported.
74-
AlwaysMarkStrings bool
75-
76-
// Set to true if you want type info to be skipped for any type that's in the Prelude
77-
// (e.g. instead of `string<String>{` seeing only `string{` is preferred, etc).
78-
//
79-
// Not yet supported.
80-
ElidePreludeTypeInfo bool
70+
// If set to true, scalar values will be omitted from the output. This is useful for representing
71+
// the structure of a graph without the data.
72+
OmitScalarValues bool
8173

8274
// Set to true if you want maps to use "complex"-style printouts:
8375
// meaning they will print their keys on separate lines than their values,
@@ -356,31 +348,41 @@ func (z *printBuf) doString(indentLevel int, printState uint8, n datamodel.Node)
356348
}
357349
z.writeString("}")
358350
case datamodel.Kind_Int:
359-
x, _ := n.AsInt()
360-
z.writeString("{")
361-
z.writeString(strconv.FormatInt(x, 10))
362-
z.writeString("}")
351+
if !z.Config.OmitScalarValues {
352+
x, _ := n.AsInt()
353+
z.writeString("{")
354+
z.writeString(strconv.FormatInt(x, 10))
355+
z.writeString("}")
356+
}
363357
case datamodel.Kind_Float:
364-
x, _ := n.AsFloat()
365-
z.writeString("{")
366-
z.writeString(strconv.FormatFloat(x, 'f', -1, 64))
367-
z.writeString("}")
358+
if !z.Config.OmitScalarValues {
359+
x, _ := n.AsFloat()
360+
z.writeString("{")
361+
z.writeString(strconv.FormatFloat(x, 'f', -1, 64))
362+
z.writeString("}")
363+
}
368364
case datamodel.Kind_String:
369-
x, _ := n.AsString()
370-
z.writeString("{")
371-
z.writeString(strconv.QuoteToGraphic(x))
372-
z.writeString("}")
365+
if !z.Config.OmitScalarValues {
366+
x, _ := n.AsString()
367+
z.writeString("{")
368+
z.writeString(strconv.QuoteToGraphic(x))
369+
z.writeString("}")
370+
}
373371
case datamodel.Kind_Bytes:
374-
x, _ := n.AsBytes()
375-
z.writeString("{")
376-
dst := make([]byte, hex.EncodedLen(len(x)))
377-
hex.Encode(dst, x)
378-
z.writeString(string(dst))
379-
z.writeString("}")
372+
if !z.Config.OmitScalarValues {
373+
x, _ := n.AsBytes()
374+
z.writeString("{")
375+
dst := make([]byte, hex.EncodedLen(len(x)))
376+
hex.Encode(dst, x)
377+
z.writeString(string(dst))
378+
z.writeString("}")
379+
}
380380
case datamodel.Kind_Link:
381-
x, _ := n.AsLink()
382-
z.writeString("{")
383-
z.writeString(x.String())
384-
z.writeString("}")
381+
if !z.Config.OmitScalarValues {
382+
x, _ := n.AsLink()
383+
z.writeString("{")
384+
z.writeString(x.String())
385+
z.writeString("}")
386+
}
385387
}
386388
}

printer/printer_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ func TestSimpleData(t *testing.T) {
9595
->}`,
9696
))
9797
})
98+
99+
t.Run("omit-scalars", func(t *testing.T) {
100+
qt.Check(t, Config{OmitScalarValues: true}.Sprint(n), qt.CmpEquals(), `map{string:string,string:string,string:map{string:string,string:string},string:list{0:int,1:int},string:list{0:float}}`)
101+
})
98102
})
99103

100104
t.Run("map-with-link-and-bytes", func(t *testing.T) {

0 commit comments

Comments
 (0)