Skip to content

Commit b052b97

Browse files
authored
add -noheader flag to super command (#6449)
1 parent 0d7daa4 commit b052b97

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

cli/outputflags/flags.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type Flags struct {
2626
forceBinary bool
2727
jsonPretty bool
2828
jsonShortcut bool
29+
noHeader bool
2930
outputFile string
3031
pretty int
3132
split string
@@ -46,6 +47,7 @@ func (f *Flags) setFlags(fs *flag.FlagSet) {
4647
fs.IntVar(&f.BSUP.FrameThresh, "bsup.framethresh", bsupio.DefaultFrameThresh,
4748
"minimum Super Binary frame size in uncompressed bytes")
4849
fs.BoolVar(&f.color, "color", true, "enable/disable color formatting for -S and db text output")
50+
fs.BoolVar(&f.CSV.NoHeader, "noheader", false, "omit header for CSV and TSV output")
4951
fs.StringVar(&f.supPersist, "persist", "",
5052
"regular expression to persist type definitions across the stream")
5153
fs.IntVar(&f.pretty, "pretty", 2,

sio/csvio/writer.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ type Writer struct {
2020
writer io.WriteCloser
2121
encoder *csv.Writer
2222
flattener *expr.Flattener
23+
header bool
2324
types map[int]struct{}
2425
first *super.TypeRecord
2526
strings []string
2627
}
2728

2829
type WriterOpts struct {
29-
Delim rune
30+
Delim rune
31+
NoHeader bool
3032
}
3133

3234
func NewWriter(w io.WriteCloser, opts WriterOpts) *Writer {
@@ -38,6 +40,7 @@ func NewWriter(w io.WriteCloser, opts WriterOpts) *Writer {
3840
writer: w,
3941
encoder: encoder,
4042
flattener: expr.NewFlattener(super.NewContext()),
43+
header: !opts.NoHeader,
4144
types: make(map[int]struct{}),
4245
}
4346
}
@@ -63,11 +66,13 @@ func (w *Writer) Write(rec super.Value) error {
6366
if w.first == nil {
6467
w.first = super.TypeRecordOf(rec.Type())
6568
var hdr []string
66-
for _, f := range rec.Fields() {
67-
hdr = append(hdr, f.Name)
68-
}
69-
if err := w.encoder.Write(hdr); err != nil {
70-
return err
69+
if w.header {
70+
for _, f := range rec.Fields() {
71+
hdr = append(hdr, f.Name)
72+
}
73+
if err := w.encoder.Write(hdr); err != nil {
74+
return err
75+
}
7176
}
7277
} else if _, ok := w.types[rec.Type().ID()]; !ok {
7378
if !fieldNamesEqual(w.first.Fields, rec.Fields()) {

sio/csvio/ztests/noheader.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
spq: pass
2+
3+
input: |
4+
{a:1,b:2}
5+
{a:"one",b:"two"}
6+
7+
output-flags: -f csv -noheader
8+
9+
output: |
10+
1,2
11+
one,two

0 commit comments

Comments
 (0)