From f6886911306caf5918b69134650755e237b722d5 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Sun, 26 Feb 2023 17:59:45 -0500 Subject: [PATCH] --ofmte, --ofmtf, --ofmtg --- docs/src/manpage.md | 3 +++ docs/src/manpage.txt | 3 +++ docs/src/reference-main-flag-list.md | 3 +++ internal/pkg/cli/option_parse.go | 33 ++++++++++++++++++++++++++++ man/manpage.txt | 3 +++ man/mlr.1 | 3 +++ test/cases/cli-ofmt/0001/cmd | 1 + test/cases/cli-ofmt/0001/experr | 0 test/cases/cli-ofmt/0001/expout | 11 ++++++++++ test/cases/cli-ofmt/0001/mlr | 1 + test/cases/cli-ofmt/0002/cmd | 1 + test/cases/cli-ofmt/0002/experr | 0 test/cases/cli-ofmt/0002/expout | 11 ++++++++++ test/cases/cli-ofmt/0002/mlr | 1 + test/cases/cli-ofmt/0003/cmd | 1 + test/cases/cli-ofmt/0003/experr | 0 test/cases/cli-ofmt/0003/expout | 11 ++++++++++ test/cases/cli-ofmt/0003/mlr | 1 + 18 files changed, 87 insertions(+) create mode 100644 test/cases/cli-ofmt/0001/cmd create mode 100644 test/cases/cli-ofmt/0001/experr create mode 100644 test/cases/cli-ofmt/0001/expout create mode 100644 test/cases/cli-ofmt/0001/mlr create mode 100644 test/cases/cli-ofmt/0002/cmd create mode 100644 test/cases/cli-ofmt/0002/experr create mode 100644 test/cases/cli-ofmt/0002/expout create mode 100644 test/cases/cli-ofmt/0002/mlr create mode 100644 test/cases/cli-ofmt/0003/cmd create mode 100644 test/cases/cli-ofmt/0003/experr create mode 100644 test/cases/cli-ofmt/0003/expout create mode 100644 test/cases/cli-ofmt/0003/mlr diff --git a/docs/src/manpage.md b/docs/src/manpage.md index 73bab7b90d..0d821bc254 100644 --- a/docs/src/manpage.md +++ b/docs/src/manpage.md @@ -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. diff --git a/docs/src/manpage.txt b/docs/src/manpage.txt index 82f9672356..3f82f06cff 100644 --- a/docs/src/manpage.txt +++ b/docs/src/manpage.txt @@ -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. diff --git a/docs/src/reference-main-flag-list.md b/docs/src/reference-main-flag-list.md index a71e0aa8ea..d9a7bbddff 100644 --- a/docs/src/reference-main-flag-list.md +++ b/docs/src/reference-main-flag-list.md @@ -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). diff --git a/internal/pkg/cli/option_parse.go b/internal/pkg/cli/option_parse.go index c9610729f6..f3644ff17e 100644 --- a/internal/pkg/cli/option_parse.go +++ b/internal/pkg/cli/option_parse.go @@ -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}", diff --git a/man/manpage.txt b/man/manpage.txt index 82f9672356..3f82f06cff 100644 --- a/man/manpage.txt +++ b/man/manpage.txt @@ -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. diff --git a/man/mlr.1 b/man/mlr.1 index 8344e77c00..f33e93f14d 100644 --- a/man/mlr.1 +++ b/man/mlr.1 @@ -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. diff --git a/test/cases/cli-ofmt/0001/cmd b/test/cases/cli-ofmt/0001/cmd new file mode 100644 index 0000000000..2c8b8f2661 --- /dev/null +++ b/test/cases/cli-ofmt/0001/cmd @@ -0,0 +1 @@ +mlr --ofmte 6 --from test/input/abixy --d2p put -f ${CASEDIR}/mlr diff --git a/test/cases/cli-ofmt/0001/experr b/test/cases/cli-ofmt/0001/experr new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/cases/cli-ofmt/0001/expout b/test/cases/cli-ofmt/0001/expout new file mode 100644 index 0000000000..531e7f0634 --- /dev/null +++ b/test/cases/cli-ofmt/0001/expout @@ -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 diff --git a/test/cases/cli-ofmt/0001/mlr b/test/cases/cli-ofmt/0001/mlr new file mode 100644 index 0000000000..135f8f3dec --- /dev/null +++ b/test/cases/cli-ofmt/0001/mlr @@ -0,0 +1 @@ +$x = $x * 10**6 diff --git a/test/cases/cli-ofmt/0002/cmd b/test/cases/cli-ofmt/0002/cmd new file mode 100644 index 0000000000..e361926b2c --- /dev/null +++ b/test/cases/cli-ofmt/0002/cmd @@ -0,0 +1 @@ +mlr --ofmtf 6 --from test/input/abixy --d2p put -f ${CASEDIR}/mlr diff --git a/test/cases/cli-ofmt/0002/experr b/test/cases/cli-ofmt/0002/experr new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/cases/cli-ofmt/0002/expout b/test/cases/cli-ofmt/0002/expout new file mode 100644 index 0000000000..5dfa1e620b --- /dev/null +++ b/test/cases/cli-ofmt/0002/expout @@ -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 diff --git a/test/cases/cli-ofmt/0002/mlr b/test/cases/cli-ofmt/0002/mlr new file mode 100644 index 0000000000..135f8f3dec --- /dev/null +++ b/test/cases/cli-ofmt/0002/mlr @@ -0,0 +1 @@ +$x = $x * 10**6 diff --git a/test/cases/cli-ofmt/0003/cmd b/test/cases/cli-ofmt/0003/cmd new file mode 100644 index 0000000000..fe5b9809b3 --- /dev/null +++ b/test/cases/cli-ofmt/0003/cmd @@ -0,0 +1 @@ +mlr --ofmtg 6 --from test/input/abixy --d2p put -f ${CASEDIR}/mlr diff --git a/test/cases/cli-ofmt/0003/experr b/test/cases/cli-ofmt/0003/experr new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/cases/cli-ofmt/0003/expout b/test/cases/cli-ofmt/0003/expout new file mode 100644 index 0000000000..b9edce3e0a --- /dev/null +++ b/test/cases/cli-ofmt/0003/expout @@ -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 diff --git a/test/cases/cli-ofmt/0003/mlr b/test/cases/cli-ofmt/0003/mlr new file mode 100644 index 0000000000..135f8f3dec --- /dev/null +++ b/test/cases/cli-ofmt/0003/mlr @@ -0,0 +1 @@ +$x = $x * 10**6