Add --no-auto-unsparsify flag

This commit is contained in:
John Kerl 2024-03-31 15:48:38 -04:00
parent 5f36b22f3f
commit 899e706bda
8 changed files with 49 additions and 6 deletions

View file

@ -2392,6 +2392,15 @@ var CSVTSVOnlyFlagSection = FlagSection{
},
},
{
name: "--no-auto-unsparsify",
help: "For CSV/TSV output: if the record keys change from one row to another, emit a blank line and a new header line. This is non-compliant with RFC 4180 but it helpful for heterogeneous data.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.WriterOptions.NoAutoUnsparsify = true
*pargi += 1
},
},
{
name: "--implicit-csv-header",
altNames: []string{"--headerless-csv-input", "--hi", "--implicit-tsv-header"},

View file

@ -134,6 +134,40 @@ type TWriterOptions struct {
// (all but JSON) -- unless the user explicitly asks to suppress that.
AutoFlatten bool
// Default CSV/TSV:
// a=1,b=2,c=3
// a=4,b=5
// leads to
// a,b,c
// 1 2,3
// 4,5, <-- note trailing empty field
// and
// a=1,b=2,c=3
// d=4,e=5
// leads to
// fatal error
//
// With this flag:
// a=1,b=2,c=3
// a=4,b=5
// leads to
// a,b,c
// 1 2,3
//
// a,b
// 4,5
//
// and
// a=1,b=2,c=3
// d=4,e=5
// leads to
// a,b,c
// 1,2,3
//
// d,e
// 4,5
NoAutoUnsparsify bool
// For floating-point numbers: "" means use the Go default.
FPOFMT string

View file

@ -46,8 +46,8 @@ func (writer *RecordWriterCSV) Write(
bufferedOutputStream *bufio.Writer,
outputIsStdout bool,
) error {
// End of record stream: nothing special for this output format
if outrec == nil {
// End of record stream: nothing special for this output format
return nil
}

View file

@ -32,8 +32,8 @@ func (writer *RecordWriterCSVLite) Write(
bufferedOutputStream *bufio.Writer,
outputIsStdout bool,
) error {
// End of record stream: nothing special for this output format
if outrec == nil {
// End of record stream: nothing special for this output format
return nil
}

View file

@ -25,8 +25,8 @@ func (writer *RecordWriterDKVP) Write(
bufferedOutputStream *bufio.Writer,
outputIsStdout bool,
) error {
// End of record stream: nothing special for this output format
if outrec == nil {
// End of record stream: nothing special for this output format
return nil
}

View file

@ -24,8 +24,8 @@ func (writer *RecordWriterNIDX) Write(
bufferedOutputStream *bufio.Writer,
outputIsStdout bool,
) error {
// End of record stream: nothing special for this output format
if outrec == nil {
// End of record stream: nothing special for this output format
return nil
}

View file

@ -40,8 +40,8 @@ func (writer *RecordWriterTSV) Write(
bufferedOutputStream *bufio.Writer,
outputIsStdout bool,
) error {
// End of record stream: nothing special for this output format
if outrec == nil {
// End of record stream: nothing special for this output format
return nil
}

View file

@ -48,8 +48,8 @@ func (writer *RecordWriterXTAB) Write(
bufferedOutputStream *bufio.Writer,
outputIsStdout bool,
) error {
// End of record stream: nothing special for this output format
if outrec == nil {
// End of record stream: nothing special for this output format
return nil
}