From 2de112374bf2254212815319633fdeb955b7e7bf Mon Sep 17 00:00:00 2001 From: Korenevskiy Denis Date: Sat, 12 Oct 2024 15:18:12 +0300 Subject: [PATCH] feat: allow to change sample column label in output table --- package.json | 4 ++-- table-converter/internal/config.go | 5 +++++ table-converter/internal/converter.go | 4 +--- table-converter/table-converter/main.go | 10 ++++++++-- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 31c917e..f8bc574 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@milaboratories/software-small-binaries", - "version": "1.11.1", + "version": "1.12.0", "description": "Small cross-platform binaries, like 'sleep' or 'hello-world', suitable for test needs", "scripts": { "cleanup": "rm -rf ./pkg-*.tgz && rm -rf ./build/ && rm -rf ./dist/", @@ -73,7 +73,7 @@ "table-converter": { "registry": "platforma-open" , - "version": "1.1.0", + "version": "1.2.0", "type": "binary", "roots": { "linux-x64": "./build/linux-x64/table-converter", diff --git a/table-converter/internal/config.go b/table-converter/internal/config.go index 43e5546..c243577 100644 --- a/table-converter/internal/config.go +++ b/table-converter/internal/config.go @@ -6,6 +6,7 @@ import ( ) const ( + DefaultSampleColumnLabel = "Sample" DefaultMetricColumnLabel = "Metric" DefaultValueColumnLabel = "Value" ) @@ -22,6 +23,7 @@ type Config struct { SampleColumnIndex int MetricColmunsSearch *regexp.Regexp + SampleColumnLabel string MetricColumnLabel string ValueColumnLabel string } @@ -39,6 +41,9 @@ func (c *Config) LoadDefaults() { } } + if c.SampleColumnLabel == "" { + c.SampleColumnLabel = DefaultSampleColumnLabel + } if c.MetricColumnLabel == "" { c.MetricColumnLabel = DefaultMetricColumnLabel } diff --git a/table-converter/internal/converter.go b/table-converter/internal/converter.go index 590ab37..c59f56a 100644 --- a/table-converter/internal/converter.go +++ b/table-converter/internal/converter.go @@ -8,8 +8,6 @@ import ( "os" ) -const SampleColumnName = "Sample" - type Converter struct { config Config } @@ -51,7 +49,7 @@ func (c *Converter) Convert(input io.Reader, output io.Writer) error { ) } - err = writer.Write([]string{SampleColumnName, c.config.MetricColumnLabel, c.config.ValueColumnLabel}) + err = writer.Write([]string{c.config.SampleColumnLabel, c.config.MetricColumnLabel, c.config.ValueColumnLabel}) if err != nil { return Wrap(err, "[output]: failed to write output table header") } diff --git a/table-converter/table-converter/main.go b/table-converter/table-converter/main.go index 6ba8bcd..108ba54 100644 --- a/table-converter/table-converter/main.go +++ b/table-converter/table-converter/main.go @@ -18,11 +18,12 @@ const ( optInputSeparator = "input-separator" optOutputSeparator = "output-separator" - optSampleColumnname = "sample-column-name" + optSampleColumnName = "sample-column-name" optSampleColumnSearch = "sample-column-search" optSampleColumnI = "sample-column-i" optMetricColumnsSearch = "metric-columns-search" + optSampleLabel = "sample-label" optMetricLabel = "metric-label" optValueLabel = "value-label" ) @@ -58,6 +59,7 @@ func configure(flags *flag.FlagSet, args []string) (conf converter.Config, err e sampleColumnI int metricColumnRE string + sampleColumnLabel string metricColumnLabel string valueColumnLabel string ) @@ -66,11 +68,12 @@ func configure(flags *flag.FlagSet, args []string) (conf converter.Config, err e flags.StringVar(&inputSeparator, optInputSeparator, "", "Separator for input file") flags.StringVar(&outputSeparator, optOutputSeparator, "", "Separator for output file") - flags.StringVar(&sampleColumnName, optSampleColumnname, "", "Name of the column that contains sample names in input table") + flags.StringVar(&sampleColumnName, optSampleColumnName, "", "Name of the column that contains sample names in input table") flags.StringVar(&sampleColumnRE, optSampleColumnSearch, "", "Regex to use when searching the column that contains sample names in input table") flags.IntVar(&sampleColumnI, optSampleColumnI, 0, "Instead of searching by name, just use column number N from the table. Left-most column has index 0") flags.StringVar(&metricColumnRE, optMetricColumnsSearch, "", "Regex to select metric columns in input table") + flags.StringVar(&sampleColumnLabel, optSampleLabel, converter.DefaultSampleColumnLabel, "Label for 'sample' column in output table") flags.StringVar(&metricColumnLabel, optMetricLabel, converter.DefaultMetricColumnLabel, "Label for 'metric' column in output table") flags.StringVar(&valueColumnLabel, optValueLabel, converter.DefaultValueColumnLabel, "Label for 'value' column in output table") @@ -124,6 +127,9 @@ func configure(flags *flag.FlagSet, args []string) (conf converter.Config, err e if outputSeparator != "" { conf.OutputFileSeparator = rune(outputSeparator[0]) } + if sampleColumnLabel != "" { + conf.SampleColumnLabel = sampleColumnLabel + } if metricColumnLabel != "" { conf.MetricColumnLabel = metricColumnLabel }