Skip to content

Commit 8cc7b36

Browse files
authored
Merge pull request #1587 from ripienaar/table_formats
Support configuring output formats for tables
2 parents e47a361 + b98bb6e commit 8cc7b36

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ require (
2020
github.com/klauspost/compress v1.18.3
2121
github.com/nats-io/jsm.go v0.3.1-0.20260116154816-a772222ebcf0
2222
github.com/nats-io/jwt/v2 v2.8.0
23-
github.com/nats-io/nats-server/v2 v2.12.4-RC.2
23+
github.com/nats-io/nats-server/v2 v2.12.4
2424
github.com/nats-io/nats.go v1.48.0
25-
github.com/nats-io/nkeys v0.4.12
25+
github.com/nats-io/nkeys v0.4.14
2626
github.com/nats-io/nuid v1.0.1
2727
github.com/prometheus/client_golang v1.23.2
2828
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1
@@ -45,7 +45,7 @@ require (
4545
github.com/beorn7/perks v1.0.1 // indirect
4646
github.com/cespare/xxhash/v2 v2.3.0 // indirect
4747
github.com/clipperhouse/stringish v0.1.1 // indirect
48-
github.com/clipperhouse/uax29/v2 v2.3.0 // indirect
48+
github.com/clipperhouse/uax29/v2 v2.4.0 // indirect
4949
github.com/google/go-tpm v0.9.8 // indirect
5050
github.com/google/uuid v1.6.0 // indirect
5151
github.com/gosuri/uilive v0.0.4 // indirect

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ github.com/choria-io/scaffold v0.0.5 h1:Nv8tY/CJtLNAmg4CqHXgY73rVuG1FCMQXRJp4VkA
2626
github.com/choria-io/scaffold v0.0.5/go.mod h1:4NvrSKLOjkMSxaTOdqNntNMJ5oE67jiu8d5PHzNBHMY=
2727
github.com/clipperhouse/stringish v0.1.1 h1:+NSqMOr3GR6k1FdRhhnXrLfztGzuG+VuFDfatpWHKCs=
2828
github.com/clipperhouse/stringish v0.1.1/go.mod h1:v/WhFtE1q0ovMta2+m+UbpZ+2/HEXNWYXQgCt4hdOzA=
29-
github.com/clipperhouse/uax29/v2 v2.3.0 h1:SNdx9DVUqMoBuBoW3iLOj4FQv3dN5mDtuqwuhIGpJy4=
30-
github.com/clipperhouse/uax29/v2 v2.3.0/go.mod h1:Wn1g7MK6OoeDT0vL+Q0SQLDz/KpfsVRgg6W7ihQeh4g=
29+
github.com/clipperhouse/uax29/v2 v2.4.0 h1:RXqE/l5EiAbA4u97giimKNlmpvkmz+GrBVTelsoXy9g=
30+
github.com/clipperhouse/uax29/v2 v2.4.0/go.mod h1:Wn1g7MK6OoeDT0vL+Q0SQLDz/KpfsVRgg6W7ihQeh4g=
3131
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
3232
github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI=
3333
github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
@@ -113,12 +113,12 @@ github.com/nats-io/jsm.go v0.3.1-0.20260116154816-a772222ebcf0 h1:LuzntHfAPnkbuP
113113
github.com/nats-io/jsm.go v0.3.1-0.20260116154816-a772222ebcf0/go.mod h1:nkGIXcioPyU76vxXSS23b4GPNuuhkPINwFFff8ISNUo=
114114
github.com/nats-io/jwt/v2 v2.8.0 h1:K7uzyz50+yGZDO5o772eRE7atlcSEENpL7P+b74JV1g=
115115
github.com/nats-io/jwt/v2 v2.8.0/go.mod h1:me11pOkwObtcBNR8AiMrUbtVOUGkqYjMQZ6jnSdVUIA=
116-
github.com/nats-io/nats-server/v2 v2.12.4-RC.2 h1:8rZP9zK2bQwWbmJ96ZSi3Jd1cFKSgHCpkua+BhWFeFA=
117-
github.com/nats-io/nats-server/v2 v2.12.4-RC.2/go.mod h1:9cS0wrU/V/TIrWyYSCpc15V66Cja0wxEvh8aL1SuFzU=
116+
github.com/nats-io/nats-server/v2 v2.12.4 h1:ZnT10v2LU2Xcoiy8ek9X6Se4YG8EuMfIfvAEuFVx1Ts=
117+
github.com/nats-io/nats-server/v2 v2.12.4/go.mod h1:5MCp/pqm5SEfsvVZ31ll1088ZTwEUdvRX1Hmh/mTTDg=
118118
github.com/nats-io/nats.go v1.48.0 h1:pSFyXApG+yWU/TgbKCjmm5K4wrHu86231/w84qRVR+U=
119119
github.com/nats-io/nats.go v1.48.0/go.mod h1:iRWIPokVIFbVijxuMQq4y9ttaBTMe0SFdlZfMDd+33g=
120-
github.com/nats-io/nkeys v0.4.12 h1:nssm7JKOG9/x4J8II47VWCL1Ds29avyiQDRn0ckMvDc=
121-
github.com/nats-io/nkeys v0.4.12/go.mod h1:MT59A1HYcjIcyQDJStTfaOY6vhy9XTUjOFo+SVsvpBg=
120+
github.com/nats-io/nkeys v0.4.14 h1:ofx8UiyHP5S4Q52/THHucCJsMWu6zhf4DLh0U2593HE=
121+
github.com/nats-io/nkeys v0.4.14/go.mod h1:seG5UKwYdZXb7M1y1vvu53mNh3xq2B6um/XUgYAgvkM=
122122
github.com/nats-io/nsc/v2 v2.12.0 h1:YCs8axEfQkbVLZDuYF4V6aJvPrDmlKJe8mWV+Rgqrzo=
123123
github.com/nats-io/nsc/v2 v2.12.0/go.mod h1:t9++ulcLFythYtRTC/2k4Mg324JTxrvpCddW/XP7j2A=
124124
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=

internal/util/tables.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2024 The NATS Authors
1+
// Copyright 2024-2026 The NATS Authors
22
// Licensed under the Apache License, Version 2.0 (the "License");
33
// you may not use this file except in compliance with the License.
44
// You may obtain a copy of the License at
@@ -17,6 +17,7 @@ import (
1717
"fmt"
1818
"os"
1919
"sort"
20+
"strings"
2021

2122
"github.com/jedib0t/go-pretty/v6/table"
2223
"github.com/jedib0t/go-pretty/v6/text"
@@ -83,7 +84,17 @@ func (t *Table) AddRow(items ...any) {
8384
}
8485

8586
func (t *Table) Render() string {
86-
return fmt.Sprintln(t.writer.Render())
87+
switch strings.ToLower(os.Getenv("NATS_TABLE_FORMAT")) {
88+
case "md", "markdown":
89+
return fmt.Sprintln(t.writer.RenderMarkdown())
90+
case "csv":
91+
return fmt.Sprintln(t.writer.RenderCSV())
92+
case "tsv":
93+
return fmt.Sprintln(t.writer.RenderTSV())
94+
default:
95+
return fmt.Sprintln(t.writer.Render())
96+
}
97+
8798
}
8899

89100
func (t *Table) RenderCSV() string {

0 commit comments

Comments
 (0)