Skip to content

Commit

Permalink
feat: allow to change sample column label in output table
Browse files Browse the repository at this point in the history
  • Loading branch information
DenKoren committed Oct 12, 2024
1 parent 476865d commit 2de1123
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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/",
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions table-converter/internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
)

const (
DefaultSampleColumnLabel = "Sample"
DefaultMetricColumnLabel = "Metric"
DefaultValueColumnLabel = "Value"
)
Expand All @@ -22,6 +23,7 @@ type Config struct {
SampleColumnIndex int
MetricColmunsSearch *regexp.Regexp

SampleColumnLabel string
MetricColumnLabel string
ValueColumnLabel string
}
Expand All @@ -39,6 +41,9 @@ func (c *Config) LoadDefaults() {
}
}

if c.SampleColumnLabel == "" {
c.SampleColumnLabel = DefaultSampleColumnLabel
}
if c.MetricColumnLabel == "" {
c.MetricColumnLabel = DefaultMetricColumnLabel
}
Expand Down
4 changes: 1 addition & 3 deletions table-converter/internal/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"os"
)

const SampleColumnName = "Sample"

type Converter struct {
config Config
}
Expand Down Expand Up @@ -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")
}
Expand Down
10 changes: 8 additions & 2 deletions table-converter/table-converter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
)
Expand All @@ -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")

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 2de1123

Please sign in to comment.