Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify the case verb, and add options #1306

Merged
merged 5 commits into from
Jun 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/src/data/cases.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
apple,ball,cat,dog,the quick brown fox
sun,tree,urchin,violet,jumped over the lazy dog
48 changes: 22 additions & 26 deletions docs/src/manpage.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,14 @@ MILLER(1) MILLER(1)
for all things with "map" in their names.

1mVERB LIST0m
altkv bar bootstrap cat check clean-whitespace count-distinct count
count-similar cut decimate downcase fill-down fill-empty filter flatten
format-values fraction gap grep group-by group-like having-fields head
histogram json-parse json-stringify join label latin1-to-utf8 least-frequent
merge-fields most-frequent nest nothing put regularize remove-empty-columns
rename reorder repeat reshape sample sec2gmtdate sec2gmt seqgen shuffle
skip-trivial-records sort sort-within-records split stats1 stats2 step summary
tac tail tee template top utf8-to-latin1 unflatten uniq unspace unsparsify
upcase
altkv bar bootstrap case cat check clean-whitespace count-distinct count
count-similar cut decimate fill-down fill-empty filter flatten format-values
fraction gap grep group-by group-like having-fields head histogram json-parse
json-stringify join label latin1-to-utf8 least-frequent merge-fields
most-frequent nest nothing put regularize remove-empty-columns rename reorder
repeat reshape sample sec2gmtdate sec2gmt seqgen shuffle skip-trivial-records
sort sort-within-records split stats1 stats2 step summary tac tail tee
template top utf8-to-latin1 unflatten uniq unspace unsparsify

1mFUNCTION LIST0m
abs acos acosh any append apply arrayify asin asinh asserting_absent
Expand Down Expand Up @@ -909,6 +908,19 @@ MILLER(1) MILLER(1)
Must be non-negative.
-h|--help Show this message.

1mcase0m
Usage: mlr case [options]
Uppercases strings in record keys and/or values.
Options:
-k Case only keys, not keys and values.
-v Case only values, not keys and values.
-f {a,b,c} Specify which field names to case (default: all)
-u Convert to uppercase
-l Convert to lowercase
-s Convert to sentence case (capitalize first letter)
-t Convert to title case (capitalize words)
-h|--help Show this message.

1mcat0m
Usage: mlr cat [options]
Passes input records directly to output. Most useful for format conversion.
Expand Down Expand Up @@ -1006,14 +1018,6 @@ MILLER(1) MILLER(1)
-n {n} Decimation factor (default 10).
-h|--help Show this message.

1mdowncase0m
Usage: mlr downcase [options]
Lowercases strings in record keys and/or values.
Options:
-k Downcase only keys, not keys and values.
-v Downcase only values, not keys and values.
-h|--help Show this message.

1mfill-down0m
Usage: mlr fill-down [options]
If a given record has a missing value for a given field, fill that from
Expand Down Expand Up @@ -2127,14 +2131,6 @@ MILLER(1) MILLER(1)
being 'b=3,c=4', then the output is the two records 'a=1,b=2,c=' and
'a=,b=3,c=4'.

1mupcase0m
Usage: mlr upcase [options]
Uppercases strings in record keys and/or values.
Options:
-k Upcase only keys, not keys and values.
-v Upcase only values, not keys and values.
-h|--help Show this message.

1mFUNCTIONS FOR FILTER/PUT0m
1mabs0m
(class=math #args=1) Absolute value.
Expand Down Expand Up @@ -3358,5 +3354,5 @@ MILLER(1) MILLER(1)



2023-06-03 MILLER(1)
2023-06-04 MILLER(1)
</pre>
48 changes: 22 additions & 26 deletions docs/src/manpage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,14 @@ MILLER(1) MILLER(1)
for all things with "map" in their names.

1mVERB LIST0m
altkv bar bootstrap cat check clean-whitespace count-distinct count
count-similar cut decimate downcase fill-down fill-empty filter flatten
format-values fraction gap grep group-by group-like having-fields head
histogram json-parse json-stringify join label latin1-to-utf8 least-frequent
merge-fields most-frequent nest nothing put regularize remove-empty-columns
rename reorder repeat reshape sample sec2gmtdate sec2gmt seqgen shuffle
skip-trivial-records sort sort-within-records split stats1 stats2 step summary
tac tail tee template top utf8-to-latin1 unflatten uniq unspace unsparsify
upcase
altkv bar bootstrap case cat check clean-whitespace count-distinct count
count-similar cut decimate fill-down fill-empty filter flatten format-values
fraction gap grep group-by group-like having-fields head histogram json-parse
json-stringify join label latin1-to-utf8 least-frequent merge-fields
most-frequent nest nothing put regularize remove-empty-columns rename reorder
repeat reshape sample sec2gmtdate sec2gmt seqgen shuffle skip-trivial-records
sort sort-within-records split stats1 stats2 step summary tac tail tee
template top utf8-to-latin1 unflatten uniq unspace unsparsify

1mFUNCTION LIST0m
abs acos acosh any append apply arrayify asin asinh asserting_absent
Expand Down Expand Up @@ -888,6 +887,19 @@ MILLER(1) MILLER(1)
Must be non-negative.
-h|--help Show this message.

1mcase0m
Usage: mlr case [options]
Uppercases strings in record keys and/or values.
Options:
-k Case only keys, not keys and values.
-v Case only values, not keys and values.
-f {a,b,c} Specify which field names to case (default: all)
-u Convert to uppercase
-l Convert to lowercase
-s Convert to sentence case (capitalize first letter)
-t Convert to title case (capitalize words)
-h|--help Show this message.

1mcat0m
Usage: mlr cat [options]
Passes input records directly to output. Most useful for format conversion.
Expand Down Expand Up @@ -985,14 +997,6 @@ MILLER(1) MILLER(1)
-n {n} Decimation factor (default 10).
-h|--help Show this message.

1mdowncase0m
Usage: mlr downcase [options]
Lowercases strings in record keys and/or values.
Options:
-k Downcase only keys, not keys and values.
-v Downcase only values, not keys and values.
-h|--help Show this message.

1mfill-down0m
Usage: mlr fill-down [options]
If a given record has a missing value for a given field, fill that from
Expand Down Expand Up @@ -2106,14 +2110,6 @@ MILLER(1) MILLER(1)
being 'b=3,c=4', then the output is the two records 'a=1,b=2,c=' and
'a=,b=3,c=4'.

1mupcase0m
Usage: mlr upcase [options]
Uppercases strings in record keys and/or values.
Options:
-k Upcase only keys, not keys and values.
-v Upcase only values, not keys and values.
-h|--help Show this message.

1mFUNCTIONS FOR FILTER/PUT0m
1mabs0m
(class=math #args=1) Absolute value.
Expand Down Expand Up @@ -3337,4 +3333,4 @@ MILLER(1) MILLER(1)



2023-06-03 MILLER(1)
2023-06-04 MILLER(1)
67 changes: 39 additions & 28 deletions docs/src/reference-verbs.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,45 @@ orange 0.4802164827586204 290
green 0.5129018241860459 1075
</pre>

## case

<pre class="pre-highlight-in-pair">
<b>mlr case --help</b>
</pre>
<pre class="pre-non-highlight-in-pair">
Usage: mlr case [options]
Uppercases strings in record keys and/or values.
Options:
-k Case only keys, not keys and values.
-v Case only values, not keys and values.
-f {a,b,c} Specify which field names to case (default: all)
-u Convert to uppercase
-l Convert to lowercase
-s Convert to sentence case (capitalize first letter)
-t Convert to title case (capitalize words)
-h|--help Show this message.
</pre>

<pre class="pre-highlight-non-pair">
<b>mlr --from test/input/cases.csv --icsv --ojson case -u</b>
</pre>

<pre class="pre-highlight-non-pair">
<b>mlr --from test/input/cases.csv --icsv --ojson case -u -k</b>
</pre>

<pre class="pre-highlight-non-pair">
<b>mlr --from test/input/cases.csv --icsv --ojson case -u -v</b>
</pre>

<pre class="pre-highlight-non-pair">
<b>mlr --from test/input/cases.csv --icsv --ojson case -k -t then case -v -s</b>
</pre>

<pre class="pre-highlight-non-pair">
<b>mlr --from test/input/cases.csv --icsv --ojson case -u -f apple,ball then case -l -f cat,dog</b>
</pre>

## cat

Most useful for format conversions (see [File Formats](file-formats.md)) and concatenating multiple same-schema CSV files to have the same header:
Expand Down Expand Up @@ -824,20 +863,6 @@ Options:
-h|--help Show this message.
</pre>

## downcase

<pre class="pre-highlight-in-pair">
<b>mlr downcase --help</b>
</pre>
<pre class="pre-non-highlight-in-pair">
Usage: mlr downcase [options]
Lowercases strings in record keys and/or values.
Options:
-k Downcase only keys, not keys and values.
-v Downcase only values, not keys and values.
-h|--help Show this message.
</pre>

## fill-down

<pre class="pre-highlight-in-pair">
Expand Down Expand Up @@ -4288,17 +4313,3 @@ a b v u w x
1 - 2 - - 3
- - 1 - 2 -
</pre>

## upcase

<pre class="pre-highlight-in-pair">
<b>mlr upcase --help</b>
</pre>
<pre class="pre-non-highlight-in-pair">
Usage: mlr upcase [options]
Uppercases strings in record keys and/or values.
Options:
-k Upcase only keys, not keys and values.
-v Upcase only values, not keys and values.
-h|--help Show this message.
</pre>
38 changes: 26 additions & 12 deletions docs/src/reference-verbs.md.in
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,32 @@ orange 0.4802164827586204 290
green 0.5129018241860459 1075
GENMD-EOF

## case

GENMD-RUN-COMMAND
mlr case --help
GENMD-EOF

GENMD-CARDIFY-HIGHLIGHT-ONE
mlr --from test/input/cases.csv --icsv --ojson case -u
GENMD-EOF

GENMD-CARDIFY-HIGHLIGHT-ONE
mlr --from test/input/cases.csv --icsv --ojson case -u -k
GENMD-EOF

GENMD-CARDIFY-HIGHLIGHT-ONE
mlr --from test/input/cases.csv --icsv --ojson case -u -v
GENMD-EOF

GENMD-CARDIFY-HIGHLIGHT-ONE
mlr --from test/input/cases.csv --icsv --ojson case -k -t then case -v -s
GENMD-EOF

GENMD-CARDIFY-HIGHLIGHT-ONE
mlr --from test/input/cases.csv --icsv --ojson case -u -f apple,ball then case -l -f cat,dog
GENMD-EOF

## cat

Most useful for format conversions (see [File Formats](file-formats.md)) and concatenating multiple same-schema CSV files to have the same header:
Expand Down Expand Up @@ -297,12 +323,6 @@ GENMD-RUN-COMMAND
mlr decimate --help
GENMD-EOF

## downcase

GENMD-RUN-COMMAND
mlr downcase --help
GENMD-EOF

## fill-down

GENMD-RUN-COMMAND
Expand Down Expand Up @@ -1294,9 +1314,3 @@ GENMD-EOF
GENMD-RUN-COMMAND
mlr --ijson --opprint unsparsify -f a,b,u,v,w,x then regularize data/sparse.json
GENMD-EOF

## upcase

GENMD-RUN-COMMAND
mlr upcase --help
GENMD-EOF
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ require (
github.com/google/pprof v0.0.0-20211214055906-6f57359322fd // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/text v0.9.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.8.0 h1:n5xxQn2i3PC0yLAbjTpNT85q/Kgzcr2gIoX9OrJUols=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
3 changes: 1 addition & 2 deletions internal/pkg/transformers/aaa_transformer_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var TRANSFORMER_LOOKUP_TABLE = []TransformerSetup{
AltkvSetup,
BarSetup,
BootstrapSetup,
CaseSetup,
CatSetup,
CheckSetup,
CleanWhitespaceSetup,
Expand All @@ -22,7 +23,6 @@ var TRANSFORMER_LOOKUP_TABLE = []TransformerSetup{
CountSimilarSetup,
CutSetup,
DecimateSetup,
DowncaseSetup,
FillDownSetup,
FillEmptySetup,
FilterSetup,
Expand Down Expand Up @@ -76,7 +76,6 @@ var TRANSFORMER_LOOKUP_TABLE = []TransformerSetup{
UniqSetup,
UnspaceSetup,
UnsparsifySetup,
UpcaseSetup,
}

func ShowHelpForTransformer(verb string) bool {
Expand Down
Loading
Loading