From bfc829a3816fa5297852892b4af068bfa872cb44 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Sat, 20 Jan 2024 13:36:28 -0500 Subject: [PATCH] Internal name-neatens (#1475) --- pkg/cli/option_parse.go | 10 +++++----- pkg/cli/option_types.go | 14 +++++++------- pkg/input/record_reader_csv.go | 2 +- pkg/input/record_reader_csvlite.go | 2 +- pkg/input/record_reader_pprint.go | 5 ++--- pkg/input/record_reader_tsv.go | 2 +- pkg/output/record_writer_csv.go | 2 +- pkg/output/record_writer_csvlite.go | 2 +- pkg/output/record_writer_pprint.go | 4 ++-- pkg/output/record_writer_tsv.go | 2 +- 10 files changed, 22 insertions(+), 23 deletions(-) diff --git a/pkg/cli/option_parse.go b/pkg/cli/option_parse.go index 00e2c94d6..aa01c17ce 100644 --- a/pkg/cli/option_parse.go +++ b/pkg/cli/option_parse.go @@ -2159,7 +2159,7 @@ var CSVTSVOnlyFlagSection = FlagSection{ altNames: []string{"--no-implicit-tsv-header"}, help: "Opposite of `--implicit-csv-header`. This is the default anyway -- the main use is for the flags to `mlr join` if you have main file(s) which are headerless but you want to join in on a file which does have a CSV/TSV header. Then you could use `mlr --csv --implicit-csv-header join --no-implicit-csv-header -l your-join-in-with-header.csv ... your-headerless.csv`.", parser: func(args []string, argc int, pargi *int, options *TOptions) { - options.ReaderOptions.UseImplicitCSVHeader = false + options.ReaderOptions.UseImplicitHeader = false *pargi += 1 }, }, @@ -2179,7 +2179,7 @@ var CSVTSVOnlyFlagSection = FlagSection{ altNames: []string{"--headerless-csv-input", "--hi", "--implicit-tsv-header"}, help: "Use 1,2,3,... as field labels, rather than from line 1 of input files. Tip: combine with `label` to recreate missing headers.", parser: func(args []string, argc int, pargi *int, options *TOptions) { - options.ReaderOptions.UseImplicitCSVHeader = true + options.ReaderOptions.UseImplicitHeader = true *pargi += 1 }, }, @@ -2189,7 +2189,7 @@ var CSVTSVOnlyFlagSection = FlagSection{ altNames: []string{"--ho", "--headerless-tsv-output"}, help: "Print only CSV/TSV data lines; do not print CSV/TSV header lines.", parser: func(args []string, argc int, pargi *int, options *TOptions) { - options.WriterOptions.HeaderlessCSVOutput = true + options.WriterOptions.HeaderlessOutput = true *pargi += 1 }, }, @@ -2198,8 +2198,8 @@ var CSVTSVOnlyFlagSection = FlagSection{ name: "-N", help: "Keystroke-saver for `--implicit-csv-header --headerless-csv-output`.", parser: func(args []string, argc int, pargi *int, options *TOptions) { - options.ReaderOptions.UseImplicitCSVHeader = true - options.WriterOptions.HeaderlessCSVOutput = true + options.ReaderOptions.UseImplicitHeader = true + options.WriterOptions.HeaderlessOutput = true *pargi += 1 }, }, diff --git a/pkg/cli/option_types.go b/pkg/cli/option_types.go index 859d67a8d..22f32658f 100644 --- a/pkg/cli/option_types.go +++ b/pkg/cli/option_types.go @@ -53,11 +53,11 @@ type TReaderOptions struct { irsWasSpecified bool allowRepeatIFSWasSpecified bool - UseImplicitCSVHeader bool - AllowRaggedCSVInput bool - CSVLazyQuotes bool - CSVTrimLeadingSpace bool - BarredPprintInput bool + UseImplicitHeader bool + AllowRaggedCSVInput bool + CSVLazyQuotes bool + CSVTrimLeadingSpace bool + BarredPprintInput bool CommentHandling TCommentHandling CommentString string @@ -96,7 +96,7 @@ type TWriterOptions struct { opsWasSpecified bool orsWasSpecified bool - HeaderlessCSVOutput bool + HeaderlessOutput bool BarredPprintOutput bool RightAlignedPPRINTOutput bool RightAlignedXTABOutput bool @@ -214,7 +214,7 @@ func DefaultWriterOptions() TWriterOptions { FLATSEP: ".", FlushOnEveryRecord: true, - HeaderlessCSVOutput: false, + HeaderlessOutput: false, WrapJSONOutputInOuterList: true, JSONOutputMultiline: true, diff --git a/pkg/input/record_reader_csv.go b/pkg/input/record_reader_csv.go index e7135e2fc..ab7c1d761 100644 --- a/pkg/input/record_reader_csv.go +++ b/pkg/input/record_reader_csv.go @@ -101,7 +101,7 @@ func (reader *RecordReaderCSV) processHandle( // Reset state for start of next input file reader.filename = filename reader.rowNumber = 0 - reader.needHeader = !reader.readerOptions.UseImplicitCSVHeader + reader.needHeader = !reader.readerOptions.UseImplicitHeader reader.header = nil csvReader := csv.NewReader(NewBOMStrippingReader(handle)) diff --git a/pkg/input/record_reader_csvlite.go b/pkg/input/record_reader_csvlite.go index 67d7ebced..3664d6ea3 100644 --- a/pkg/input/record_reader_csvlite.go +++ b/pkg/input/record_reader_csvlite.go @@ -70,7 +70,7 @@ func NewRecordReaderCSVLite( useVoidRep: false, voidRep: "", } - if reader.readerOptions.UseImplicitCSVHeader { + if reader.readerOptions.UseImplicitHeader { reader.recordBatchGetter = getRecordBatchImplicitCSVHeader } else { reader.recordBatchGetter = getRecordBatchExplicitCSVHeader diff --git a/pkg/input/record_reader_pprint.go b/pkg/input/record_reader_pprint.go index 9a2f279f3..8adad8756 100644 --- a/pkg/input/record_reader_pprint.go +++ b/pkg/input/record_reader_pprint.go @@ -49,7 +49,7 @@ func NewRecordReaderPPRINT( separatorMatcher: regexp.MustCompile(`^\+[-+]*\+`), fieldSplitter: newFieldSplitter(readerOptions), } - if reader.readerOptions.UseImplicitCSVHeader { + if reader.readerOptions.UseImplicitHeader { reader.recordBatchGetter = getRecordBatchImplicitPprintHeader } else { reader.recordBatchGetter = getRecordBatchExplicitPprintHeader @@ -67,8 +67,7 @@ func NewRecordReaderPPRINT( useVoidRep: true, voidRep: "-", } - // XXX RENAME THERE - if reader.readerOptions.UseImplicitCSVHeader { + if reader.readerOptions.UseImplicitHeader { reader.recordBatchGetter = getRecordBatchImplicitCSVHeader } else { reader.recordBatchGetter = getRecordBatchExplicitCSVHeader diff --git a/pkg/input/record_reader_tsv.go b/pkg/input/record_reader_tsv.go index d3b9d75a3..a0d77aec4 100644 --- a/pkg/input/record_reader_tsv.go +++ b/pkg/input/record_reader_tsv.go @@ -52,7 +52,7 @@ func NewRecordReaderTSV( recordsPerBatch: recordsPerBatch, fieldSplitter: newFieldSplitter(readerOptions), } - if reader.readerOptions.UseImplicitCSVHeader { + if reader.readerOptions.UseImplicitHeader { reader.recordBatchGetter = getRecordBatchImplicitTSVHeader } else { reader.recordBatchGetter = getRecordBatchExplicitTSVHeader diff --git a/pkg/output/record_writer_csv.go b/pkg/output/record_writer_csv.go index fd4801d29..947400275 100644 --- a/pkg/output/record_writer_csv.go +++ b/pkg/output/record_writer_csv.go @@ -77,7 +77,7 @@ func (writer *RecordWriterCSV) Write( needToPrintHeader = true } - if needToPrintHeader && !writer.writerOptions.HeaderlessCSVOutput { + if needToPrintHeader && !writer.writerOptions.HeaderlessOutput { fields := make([]string, outrec.FieldCount) i := 0 for pe := outrec.Head; pe != nil; pe = pe.Next { diff --git a/pkg/output/record_writer_csvlite.go b/pkg/output/record_writer_csvlite.go index 251cf9580..ced670c13 100644 --- a/pkg/output/record_writer_csvlite.go +++ b/pkg/output/record_writer_csvlite.go @@ -58,7 +58,7 @@ func (writer *RecordWriterCSVLite) Write( needToPrintHeader = true } - if needToPrintHeader && !writer.writerOptions.HeaderlessCSVOutput { + if needToPrintHeader && !writer.writerOptions.HeaderlessOutput { for pe := outrec.Head; pe != nil; pe = pe.Next { bufferedOutputStream.WriteString(colorizer.MaybeColorizeKey(pe.Key, outputIsStdout)) diff --git a/pkg/output/record_writer_pprint.go b/pkg/output/record_writer_pprint.go index 79d49b316..2fd4aaa70 100644 --- a/pkg/output/record_writer_pprint.go +++ b/pkg/output/record_writer_pprint.go @@ -155,7 +155,7 @@ func (writer *RecordWriterPPRINT) writeHeterogenousListNonBarred( outrec := e.Value.(*mlrval.Mlrmap) // Print header line - if onFirst && !writer.writerOptions.HeaderlessCSVOutput { + if onFirst && !writer.writerOptions.HeaderlessOutput { for pe := outrec.Head; pe != nil; pe = pe.Next { if !writer.writerOptions.RightAlignedPPRINTOutput { // left-align if pe.Next != nil { @@ -257,7 +257,7 @@ func (writer *RecordWriterPPRINT) writeHeterogenousListBarred( outrec := e.Value.(*mlrval.Mlrmap) // Print header line - if onFirst && !writer.writerOptions.HeaderlessCSVOutput { + if onFirst && !writer.writerOptions.HeaderlessOutput { bufferedOutputStream.WriteString(horizontalStart) for pe := outrec.Head; pe != nil; pe = pe.Next { bufferedOutputStream.WriteString(horizontalBars[pe.Key]) diff --git a/pkg/output/record_writer_tsv.go b/pkg/output/record_writer_tsv.go index 149ac9530..48db403d8 100644 --- a/pkg/output/record_writer_tsv.go +++ b/pkg/output/record_writer_tsv.go @@ -66,7 +66,7 @@ func (writer *RecordWriterTSV) Write( needToPrintHeader = true } - if needToPrintHeader && !writer.writerOptions.HeaderlessCSVOutput { + if needToPrintHeader && !writer.writerOptions.HeaderlessOutput { for pe := outrec.Head; pe != nil; pe = pe.Next { bufferedOutputStream.WriteString( colorizer.MaybeColorizeKey(