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

Add --ofmte, --ofmtf, --ofmtg command-line flags #1206

Merged
merged 1 commit into from
Feb 28, 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
3 changes: 3 additions & 0 deletions docs/src/manpage.md
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,9 @@ MILLER(1) MILLER(1)
floating-point numbers. If not specified, default
formatting is used. See also the `fmtnum` function
and the `format-values` verb.
--ofmte {n} Use --ofmte 6 as shorthand for --ofmt %.6e, etc.
--ofmtf {n} Use --ofmtf 6 as shorthand for --ofmt %.6f, etc.
--ofmtg {n} Use --ofmtg 6 as shorthand for --ofmt %.6g, etc.
--records-per-batch {n} This is an internal parameter for maximum number of
records in a batch size. Normally this does not need
to be modified.
Expand Down
3 changes: 3 additions & 0 deletions docs/src/manpage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,9 @@ MILLER(1) MILLER(1)
floating-point numbers. If not specified, default
formatting is used. See also the `fmtnum` function
and the `format-values` verb.
--ofmte {n} Use --ofmte 6 as shorthand for --ofmt %.6e, etc.
--ofmtf {n} Use --ofmtf 6 as shorthand for --ofmt %.6f, etc.
--ofmtg {n} Use --ofmtg 6 as shorthand for --ofmt %.6g, etc.
--records-per-batch {n} This is an internal parameter for maximum number of
records in a batch size. Normally this does not need
to be modified.
Expand Down
3 changes: 3 additions & 0 deletions docs/src/reference-main-flag-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ These are flags which don't fit into any other category.
* `--no-hash-records`: See --hash-records.
* `--nr-progress-mod {m}`: With m a positive integer: print filename and record count to os.Stderr every m input records.
* `--ofmt {format}`: E.g. `%.18f`, `%.0f`, `%9.6e`. Please use sprintf-style codes (https://pkg.go.dev/fmt) for floating-point numbers. If not specified, default formatting is used. See also the `fmtnum` function and the `format-values` verb.
* `--ofmte {n}`: Use --ofmte 6 as shorthand for --ofmt %.6e, etc.
* `--ofmtf {n}`: Use --ofmtf 6 as shorthand for --ofmt %.6f, etc.
* `--ofmtg {n}`: Use --ofmtg 6 as shorthand for --ofmt %.6g, etc.
* `--records-per-batch {n}`: This is an internal parameter for maximum number of records in a batch size. Normally this does not need to be modified.
* `--seed {n}`: with `n` of the form `12345678` or `0xcafefeed`. For `put`/`filter` `urand`, `urandint`, and `urand32`.
* `--tz {timezone}`: Specify timezone, overriding `$TZ` environment variable (if any).
Expand Down
33 changes: 33 additions & 0 deletions internal/pkg/cli/option_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -2743,6 +2743,39 @@ var MiscFlagSection = FlagSection{
},
},

{
name: "--ofmte",
arg: "{n}",
help: "Use --ofmte 6 as shorthand for --ofmt %.6e, etc.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
CheckArgCount(args, *pargi, argc, 2)
options.WriterOptions.FPOFMT = "%." + args[*pargi+1] + "e"
*pargi += 2
},
},

{
name: "--ofmtf",
arg: "{n}",
help: "Use --ofmtf 6 as shorthand for --ofmt %.6f, etc.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
CheckArgCount(args, *pargi, argc, 2)
options.WriterOptions.FPOFMT = "%." + args[*pargi+1] + "f"
*pargi += 2
},
},

{
name: "--ofmtg",
arg: "{n}",
help: "Use --ofmtg 6 as shorthand for --ofmt %.6g, etc.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
CheckArgCount(args, *pargi, argc, 2)
options.WriterOptions.FPOFMT = "%." + args[*pargi+1] + "g"
*pargi += 2
},
},

{
name: "--load",
arg: "{filename}",
Expand Down
3 changes: 3 additions & 0 deletions man/manpage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,9 @@ MILLER(1) MILLER(1)
floating-point numbers. If not specified, default
formatting is used. See also the `fmtnum` function
and the `format-values` verb.
--ofmte {n} Use --ofmte 6 as shorthand for --ofmt %.6e, etc.
--ofmtf {n} Use --ofmtf 6 as shorthand for --ofmt %.6f, etc.
--ofmtg {n} Use --ofmtg 6 as shorthand for --ofmt %.6g, etc.
--records-per-batch {n} This is an internal parameter for maximum number of
records in a batch size. Normally this does not need
to be modified.
Expand Down
3 changes: 3 additions & 0 deletions man/mlr.1
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,9 @@ These are flags which don't fit into any other category.
floating-point numbers. If not specified, default
formatting is used. See also the `fmtnum` function
and the `format-values` verb.
--ofmte {n} Use --ofmte 6 as shorthand for --ofmt %.6e, etc.
--ofmtf {n} Use --ofmtf 6 as shorthand for --ofmt %.6f, etc.
--ofmtg {n} Use --ofmtg 6 as shorthand for --ofmt %.6g, etc.
--records-per-batch {n} This is an internal parameter for maximum number of
records in a batch size. Normally this does not need
to be modified.
Expand Down
1 change: 1 addition & 0 deletions test/cases/cli-ofmt/0001/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr --ofmte 6 --from test/input/abixy --d2p put -f ${CASEDIR}/mlr
Empty file added test/cases/cli-ofmt/0001/experr
Empty file.
11 changes: 11 additions & 0 deletions test/cases/cli-ofmt/0001/expout
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
a b i x y
pan pan 1 3.467901e+05 7.268029e-01
eks pan 2 7.586800e+05 5.221511e-01
wye wye 3 2.046033e+05 3.383185e-01
eks wye 4 3.813994e+05 1.341887e-01
wye pan 5 5.732889e+05 8.636245e-01
zee pan 6 5.271262e+05 4.932213e-01
eks zee 7 6.117841e+05 1.878849e-01
zee wye 8 5.985540e+05 9.761814e-01
hat wye 9 3.144188e+04 7.495508e-01
pan wye 10 5.026260e+05 9.526184e-01
1 change: 1 addition & 0 deletions test/cases/cli-ofmt/0001/mlr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$x = $x * 10**6
1 change: 1 addition & 0 deletions test/cases/cli-ofmt/0002/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr --ofmtf 6 --from test/input/abixy --d2p put -f ${CASEDIR}/mlr
Empty file added test/cases/cli-ofmt/0002/experr
Empty file.
11 changes: 11 additions & 0 deletions test/cases/cli-ofmt/0002/expout
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
a b i x y
pan pan 1 346790.144338 0.726803
eks pan 2 758679.964790 0.522151
wye wye 3 204603.305766 0.338319
eks wye 4 381399.393871 0.134189
wye pan 5 573288.919802 0.863624
zee pan 6 527126.160092 0.493221
eks zee 7 611784.060568 0.187885
zee wye 8 598554.009106 0.976181
hat wye 9 31441.876461 0.749551
pan wye 10 502626.005541 0.952618
1 change: 1 addition & 0 deletions test/cases/cli-ofmt/0002/mlr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$x = $x * 10**6
1 change: 1 addition & 0 deletions test/cases/cli-ofmt/0003/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr --ofmtg 6 --from test/input/abixy --d2p put -f ${CASEDIR}/mlr
Empty file added test/cases/cli-ofmt/0003/experr
Empty file.
11 changes: 11 additions & 0 deletions test/cases/cli-ofmt/0003/expout
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
a b i x y
pan pan 1 346790 0.726803
eks pan 2 758680 0.522151
wye wye 3 204603 0.338319
eks wye 4 381399 0.134189
wye pan 5 573289 0.863624
zee pan 6 527126 0.493221
eks zee 7 611784 0.187885
zee wye 8 598554 0.976181
hat wye 9 31441.9 0.749551
pan wye 10 502626 0.952618
1 change: 1 addition & 0 deletions test/cases/cli-ofmt/0003/mlr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$x = $x * 10**6