From 1e8cfc322844da5448221cc3d7471d1ed8cff80c Mon Sep 17 00:00:00 2001 From: Torin Sandall Date: Thu, 26 Oct 2023 13:43:55 -0700 Subject: [PATCH] cmd: fix inspect to omit unnecessary whitespace Signed-off-by: Torin Sandall --- cmd/inspect.go | 15 ++++++++++----- cmd/inspect_test.go | 13 +++++++------ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/cmd/inspect.go b/cmd/inspect.go index 27a42f4dd03..a23bc6c5b54 100644 --- a/cmd/inspect.go +++ b/cmd/inspect.go @@ -310,11 +310,16 @@ func printList(out io.Writer, list []listEntry, separator string) { } } for _, e := range list { - line := fmt.Sprintf(" %s%s%s%s", - e.key, - separator, - strings.Repeat(" ", keyLength-len(e.key)), - e.value) + var line string + if len(e.value) > 0 { + line = fmt.Sprintf(" %s%s%s%s", + e.key, + separator, + strings.Repeat(" ", keyLength-len(e.key)), + e.value) + } else { + line = fmt.Sprintf(" %v", e.key) + } fmt.Fprintln(out, truncateStr(line, pageWidth)) } } diff --git a/cmd/inspect_test.go b/cmd/inspect_test.go index 87bb9197912..e83967ab729 100644 --- a/cmd/inspect_test.go +++ b/cmd/inspect_test.go @@ -55,6 +55,7 @@ func TestDoInspect(t *testing.T) { } res := `{ + "capabilities": {}, "manifest": {"revision": "rev", "roots": ["foo", "bar", "fuz", "baz", "a", "x"]}, "signatures_config": {}, "namespaces": {"data": ["/data.json"], "data.foo": ["/example/foo.rego"]} @@ -300,7 +301,7 @@ Schemas: input: {"type":"boolean"} Related Resources: - https://pkg + https://pkg https://pkg rr-pkg-note Custom: @@ -326,7 +327,7 @@ Schemas: input: {"type":"integer"} Related Resources: - https://doc + https://doc https://doc rr-doc-note Custom: @@ -352,7 +353,7 @@ Schemas: input: {"type":"string"} Related Resources: - https://rule + https://rule https://rule rr-rule-note Custom: @@ -493,7 +494,7 @@ Schemas: input: {"type":"boolean"} Related Resources: - https://pkg + https://pkg https://pkg rr-pkg-note Custom: @@ -526,7 +527,7 @@ Schemas: input: {"type":"integer"} Related Resources: - https://doc + https://doc https://doc rr-doc-note Custom: @@ -552,7 +553,7 @@ Schemas: input: {"type":"string"} Related Resources: - https://rule + https://rule https://rule rr-rule-note Custom: