-
Notifications
You must be signed in to change notification settings - Fork 222
/
Copy pathoption_parse.go
3352 lines (3092 loc) · 115 KB
/
option_parse.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ================================================================
// Items which might better belong in miller/cli, but which are placed in a
// deeper package to avoid a package-dependency cycle between miller/cli and
// miller/transforming.
// ================================================================
package cli
import (
"bufio"
"errors"
"fmt"
"io"
"os"
"strings"
"github.com/mattn/go-isatty"
"github.com/johnkerl/miller/v6/pkg/colorizer"
"github.com/johnkerl/miller/v6/pkg/lib"
"github.com/johnkerl/miller/v6/pkg/mlrval"
)
// FinalizeReaderOptions does a few things.
// - If a file format was specified but one or more separators were not, a
// default specific to that file format is applied.
// - Computing regexes for IPS and IFS, and unbackslashing IRS. This is
// because the '\n' at the command line which is Go "\\n" (a backslash and an
// n) needs to become the single newline character, and likewise for "\t", etc.
// - IFS/IPS can have escapes like "\x1f" which aren't valid regex literals
// so we unhex them. For example, from "\x1f" -- the four bytes '\', 'x', '1', 'f'
// -- to the single byte with hex code 0x1f.
func FinalizeReaderOptions(readerOptions *TReaderOptions) error {
readerOptions.IFS = lib.UnhexStringLiteral(readerOptions.IFS)
readerOptions.IPS = lib.UnhexStringLiteral(readerOptions.IPS)
if !readerOptions.ifsWasSpecified {
readerOptions.IFS = defaultFSes[readerOptions.InputFileFormat]
}
if !readerOptions.ipsWasSpecified {
readerOptions.IPS = defaultPSes[readerOptions.InputFileFormat]
}
if !readerOptions.irsWasSpecified {
readerOptions.IRS = defaultRSes[readerOptions.InputFileFormat]
}
if !readerOptions.allowRepeatIFSWasSpecified {
// Special case for Miller 6 upgrade -- now that we have regexing for mixes of tabs
// and spaces, that should now be the default for NIDX. But *only* for NIDX format,
// and if IFS wasn't specified.
if readerOptions.InputFileFormat == "nidx" && !readerOptions.ifsWasSpecified {
readerOptions.IFSRegex = lib.CompileMillerRegexOrDie(WHITESPACE_REGEX)
} else {
readerOptions.AllowRepeatIFS = defaultAllowRepeatIFSes[readerOptions.InputFileFormat]
}
}
readerOptions.IFS = lib.UnbackslashStringLiteral(readerOptions.IFS)
readerOptions.IPS = lib.UnbackslashStringLiteral(readerOptions.IPS)
readerOptions.IRS = lib.UnbackslashStringLiteral(readerOptions.IRS)
if readerOptions.IRS == "" {
return errors.New("empty IRS")
}
return nil
}
// FinalizeWriterOptions unbackslashes OPS, OFS, and ORS. This is because
// because the '\n' at the command line which is Go "\\n" (a backslash and an
// n) needs to become the single newline character., and likewise for "\t", etc.
func FinalizeWriterOptions(writerOptions *TWriterOptions) error {
if !writerOptions.ofsWasSpecified {
writerOptions.OFS = defaultFSes[writerOptions.OutputFileFormat]
}
if !writerOptions.opsWasSpecified {
writerOptions.OPS = defaultPSes[writerOptions.OutputFileFormat]
}
if !writerOptions.orsWasSpecified {
writerOptions.ORS = defaultRSes[writerOptions.OutputFileFormat]
}
// If output is a terminal, fflush on every record. Otherwise, use default
// buffering (flush every some number of KB or on EOF). This is a
// significant performance improvement for large files, as we invoke
// syscall.write (with its invocation overhead) far less frequently.
if !writerOptions.flushOnEveryRecordWasSpecified {
writerOptions.FlushOnEveryRecord = isatty.IsTerminal(os.Stdout.Fd())
}
writerOptions.OFS = lib.UnbackslashStringLiteral(writerOptions.OFS)
writerOptions.OPS = lib.UnbackslashStringLiteral(writerOptions.OPS)
writerOptions.ORS = lib.UnbackslashStringLiteral(writerOptions.ORS)
return nil
}
// ================================================================
var FLAG_TABLE = FlagTable{
sections: []*FlagSection{
&LegacyFlagSection,
&SeparatorFlagSection,
&FileFormatFlagSection,
&FormatConversionKeystrokeSaverFlagSection,
&CSVTSVOnlyFlagSection,
&JSONOnlyFlagSection,
&PPRINTOnlyFlagSection,
&CompressedDataFlagSection,
&CommentsInDataFlagSection,
&OutputColorizationFlagSection,
&FlattenUnflattenFlagSection,
&ProfilingFlagSection,
&MiscFlagSection,
},
}
func init() {
FLAG_TABLE.Sort()
}
// ================================================================
// SEPARATOR FLAGS
func SeparatorPrintInfo() {
fmt.Println(`See the Separators doc page for more about record separators, field
separators, and pair separators. Also see the File formats doc page, or
` + "`mlr help file-formats`" + `, for more about the file formats Miller supports.
In brief:
* For DKVP records like ` + "`x=1,y=2,z=3`" + `, the fields are separated by a comma,
the key-value pairs are separated by a comma, and each record is separated
from the next by a newline.
* Each file format has its own default separators.
* Most formats, such as CSV, don't support pair-separators: keys are on the CSV
header line and values are on each CSV data line; keys and values are not
placed next to one another.
* Some separators are not programmable: for example JSON uses a colon as a
pair separator but this is non-modifiable in the JSON spec.
* You can set separators differently between Miller's input and output --
hence ` + "`--ifs`" + ` and ` + "`--ofs`" + `, etc.
Notes about line endings:
* Default line endings (` + "`--irs`" + ` and ` + "`--ors`" + `) are newline
which is interpreted to accept carriage-return/newline files (e.g. on Windows)
for input, and to produce platform-appropriate line endings on output.
Notes about all other separators:
* IPS/OPS are only used for DKVP and XTAB formats, since only in these formats
do key-value pairs appear juxtaposed.
* IRS/ORS are ignored for XTAB format. Nominally IFS and OFS are newlines;
XTAB records are separated by two or more consecutive IFS/OFS -- i.e.
a blank line. Everything above about ` + "`--irs/--ors/--rs auto`" + ` becomes ` + "`--ifs/--ofs/--fs`" + `
auto for XTAB format. (XTAB's default IFS/OFS are "auto".)
* OFS must be single-character for PPRINT format. This is because it is used
with repetition for alignment; multi-character separators would make
alignment impossible.
* OPS may be multi-character for XTAB format, in which case alignment is
disabled.
* FS/PS are ignored for markdown format; RS is used.
* All FS and PS options are ignored for JSON format, since they are not relevant
to the JSON format.
* You can specify separators in any of the following ways, shown by example:
- Type them out, quoting as necessary for shell escapes, e.g.
` + "`--fs '|' --ips :`" + `
- C-style escape sequences, e.g. ` + "`--rs '\\r\\n' --fs '\\t'`" + `.
- To avoid backslashing, you can use any of the following names:`)
fmt.Println()
// Go doesn't preserve insertion order in its arrays so here we are inlining a sort.
aliases := lib.GetArrayKeysSorted(SEPARATOR_NAMES_TO_VALUES)
for _, alias := range aliases {
// Really absurd level of indent needed to get fixed-with font in mkdocs here,
// I don't know why. Usually it only takes 4, not 10.
fmt.Printf(" %-10s = \"%s\"\n", alias, SEPARATOR_NAMES_TO_VALUES[alias])
}
fmt.Println()
fmt.Println(" - Similarly, you can use the following for `--ifs-regex` and `--ips-regex`:")
fmt.Println()
aliases = lib.GetArrayKeysSorted(SEPARATOR_REGEX_NAMES_TO_VALUES)
for _, alias := range aliases {
fmt.Printf(" %-10s = \"%s\"\n", alias, SEPARATOR_REGEX_NAMES_TO_VALUES[alias])
}
fmt.Println()
fmt.Println("* Default separators by format:")
fmt.Println()
formats := lib.GetArrayKeysSorted(defaultFSes)
// Really absurd level of indent needed to get fixed-with font in mkdocs here,
// I don't know why. Usually it only takes 4, not 8.
fmt.Printf(" %-8s %-6s %-6s %-s\n", "Format", "FS", "PS", "RS")
for _, format := range formats {
defaultFS := "\"" + strings.ReplaceAll(defaultFSes[format], "\n", "\\n") + "\""
defaultPS := "\"" + strings.ReplaceAll(defaultPSes[format], "\n", "\\n") + "\""
defaultRS := "\"" + strings.ReplaceAll(defaultRSes[format], "\n", "\\n") + "\""
if defaultFS == "\"N/A\"" {
defaultFS = "N/A"
}
if defaultPS == "\"N/A\"" {
defaultPS = "N/A"
}
if defaultRS == "\"N/A\"" {
defaultRS = "N/A"
}
fmt.Printf(" %-8s %-6s %-6s %-s\n", format, defaultFS, defaultPS, defaultRS)
}
}
func ListSeparatorAliasesForOnlineHelp() {
// Go doesn't preserve insertion order in its arrays so here we are inlining a sort.
aliases := lib.GetArrayKeysSorted(SEPARATOR_NAMES_TO_VALUES)
for _, alias := range aliases {
// Really absurd level of indent needed to get fixed-with font in mkdocs here,
// I don't know why. Usually it only takes 4, not 10.
fmt.Printf("%-10s = \"%s\"\n", alias, SEPARATOR_NAMES_TO_VALUES[alias])
}
}
func ListSeparatorRegexAliasesForOnlineHelp() {
// Go doesn't preserve insertion order in its arrays so here we are inlining a sort.
aliases := lib.GetArrayKeysSorted(SEPARATOR_REGEX_NAMES_TO_VALUES)
for _, alias := range aliases {
// Really absurd level of indent needed to get fixed-with font in mkdocs here,
// I don't know why. Usually it only takes 4, not 10.
fmt.Printf("%-10s = \"%s\"\n", alias, SEPARATOR_REGEX_NAMES_TO_VALUES[alias])
}
}
func init() { SeparatorFlagSection.Sort() }
var SeparatorFlagSection = FlagSection{
name: "Separator flags",
infoPrinter: SeparatorPrintInfo,
flags: []Flag{
{
name: "--ifs",
arg: "{string}",
help: "Specify FS for input.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
CheckArgCount(args, *pargi, argc, 2)
// Backward compatibility with Miller <= 5. Auto-inference of
// LF vs CR/LF line endings is handled within Go libraries so
// we needn't do anything ourselves.
if args[*pargi+1] != "auto" {
options.ReaderOptions.IFS = SeparatorFromArg(args[*pargi+1])
options.ReaderOptions.ifsWasSpecified = true
}
*pargi += 2
},
},
{
name: "--ifs-regex",
arg: "{string}",
help: "Specify FS for input as a regular expression.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
CheckArgCount(args, *pargi, argc, 2)
// Backward compatibility with Miller <= 5. Auto-inference of
// LF vs CR/LF line endings is handled within Go libraries so
// we needn't do anything ourselves.
if args[*pargi+1] != "auto" {
options.ReaderOptions.IFSRegex = lib.CompileMillerRegexOrDie(SeparatorRegexFromArg(args[*pargi+1]))
options.ReaderOptions.ifsWasSpecified = true
}
*pargi += 2
},
},
{
name: "--ips",
arg: "{string}",
help: "Specify PS for input.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
CheckArgCount(args, *pargi, argc, 2)
options.ReaderOptions.IPS = SeparatorFromArg(args[*pargi+1])
options.ReaderOptions.ipsWasSpecified = true
*pargi += 2
},
},
{
name: "--ips-regex",
arg: "{string}",
help: "Specify PS for input as a regular expression.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
CheckArgCount(args, *pargi, argc, 2)
options.ReaderOptions.IPSRegex = lib.CompileMillerRegexOrDie(SeparatorRegexFromArg(args[*pargi+1]))
options.ReaderOptions.ipsWasSpecified = true
*pargi += 2
},
},
{
name: "--irs",
arg: "{string}",
help: "Specify RS for input.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
CheckArgCount(args, *pargi, argc, 2)
// Backward compatibility with Miller <= 5. Auto-inference of
// LF vs CR/LF line endings is handled within Go libraries so
// we needn't do anything ourselves.
if args[*pargi+1] != "auto" {
options.ReaderOptions.IRS = SeparatorFromArg(args[*pargi+1])
options.ReaderOptions.irsWasSpecified = true
}
*pargi += 2
},
},
{
name: "--repifs",
help: "Let IFS be repeated: e.g. for splitting on multiple spaces.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.AllowRepeatIFS = true
options.ReaderOptions.allowRepeatIFSWasSpecified = true
*pargi += 1
},
},
{
name: "--ors",
arg: "{string}",
help: "Specify RS for output.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
CheckArgCount(args, *pargi, argc, 2)
// Backward compatibility with Miller <= 5. Auto-inference of
// LF vs CR/LF line endings is handled within Go libraries so
// we needn't do anything ourselves.
if args[*pargi+1] != "auto" {
options.WriterOptions.ORS = SeparatorFromArg(args[*pargi+1])
options.WriterOptions.orsWasSpecified = true
}
*pargi += 2
},
},
{
name: "--ofs",
arg: "{string}",
help: "Specify FS for output.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
CheckArgCount(args, *pargi, argc, 2)
options.WriterOptions.OFS = SeparatorFromArg(args[*pargi+1])
options.WriterOptions.ofsWasSpecified = true
*pargi += 2
},
},
{
name: "--ops",
arg: "{string}",
help: "Specify PS for output.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
CheckArgCount(args, *pargi, argc, 2)
options.WriterOptions.OPS = SeparatorFromArg(args[*pargi+1])
options.WriterOptions.opsWasSpecified = true
*pargi += 2
},
},
{
name: "--rs",
arg: "{string}",
help: "Specify RS for input and output.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
CheckArgCount(args, *pargi, argc, 2)
// Backward compatibility with Miller <= 5. Auto-inference of
// LF vs CR/LF line endings is handled within Go libraries so
// we needn't do anything ourselves.
if args[*pargi+1] != "auto" {
options.ReaderOptions.IRS = SeparatorFromArg(args[*pargi+1])
options.WriterOptions.ORS = SeparatorFromArg(args[*pargi+1])
options.ReaderOptions.irsWasSpecified = true
options.WriterOptions.orsWasSpecified = true
}
*pargi += 2
},
},
{
name: "--fs",
arg: "{string}",
help: "Specify FS for input and output.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
CheckArgCount(args, *pargi, argc, 2)
// Backward compatibility with Miller <= 5. Auto-inference of
// LF vs CR/LF line endings is handled within Go libraries so
// we needn't do anything ourselves.
if args[*pargi+1] != "auto" {
options.ReaderOptions.IFS = SeparatorFromArg(args[*pargi+1])
options.WriterOptions.OFS = SeparatorFromArg(args[*pargi+1])
options.ReaderOptions.ifsWasSpecified = true
options.WriterOptions.ofsWasSpecified = true
}
*pargi += 2
},
},
{
name: "--ps",
arg: "{string}",
help: "Specify PS for input and output.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
CheckArgCount(args, *pargi, argc, 2)
options.ReaderOptions.IPS = SeparatorFromArg(args[*pargi+1])
options.WriterOptions.OPS = SeparatorFromArg(args[*pargi+1])
options.ReaderOptions.ipsWasSpecified = true
options.WriterOptions.opsWasSpecified = true
*pargi += 2
},
},
},
}
// ================================================================
// JSON-ONLY FLAGS
func JSONOnlyPrintInfo() {
fmt.Println("These are flags which are applicable to JSON output format.")
}
func init() { JSONOnlyFlagSection.Sort() }
var JSONOnlyFlagSection = FlagSection{
name: "JSON-only flags",
infoPrinter: JSONOnlyPrintInfo,
flags: []Flag{
{
name: "--jvstack",
help: "Put one key-value pair per line for JSON output (multi-line output). This is the default for JSON output format.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.WriterOptions.JSONOutputMultiline = true
*pargi += 1
},
},
{
name: "--no-jvstack",
help: "Put objects/arrays all on one line for JSON output. This is the default for JSON Lines output format.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.WriterOptions.JSONOutputMultiline = false
*pargi += 1
},
},
{
name: "--jlistwrap",
altNames: []string{"--jl"},
help: "Wrap JSON output in outermost `[ ]`. This is the default for JSON output format.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.WriterOptions.WrapJSONOutputInOuterList = true
*pargi += 1
},
},
{
name: "--no-jlistwrap",
help: "Do not wrap JSON output in outermost `[ ]`. This is the default for JSON Lines output format.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.WriterOptions.WrapJSONOutputInOuterList = false
*pargi += 1
},
},
{
name: "--jvquoteall",
help: "Force all JSON values -- recursively into lists and object -- to string.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.WriterOptions.JVQuoteAll = true
*pargi += 1
},
},
},
}
// ================================================================
// PPRINT-ONLY FLAGS
func PPRINTOnlyPrintInfo() {
fmt.Println("These are flags which are applicable to PPRINT format.")
}
func init() { PPRINTOnlyFlagSection.Sort() }
var PPRINTOnlyFlagSection = FlagSection{
name: "PPRINT-only flags",
infoPrinter: PPRINTOnlyPrintInfo,
flags: []Flag{
{
name: "--right",
help: "Right-justifies all fields for PPRINT output.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.WriterOptions.RightAlignedPPRINTOutput = true
*pargi += 1
},
},
{
name: "--barred",
altNames: []string{"--barred-output"},
help: "Prints a border around PPRINT output.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.WriterOptions.BarredPprintOutput = true
*pargi += 1
},
},
{
name: "--barred-input",
help: "When used in conjunction with --pprint, accepts barred input.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.BarredPprintInput = true
options.ReaderOptions.IFS = "|"
*pargi += 1
},
},
},
}
// ================================================================
// LEGACY FLAGS
func LegacyFlagInfoPrint() {
fmt.Println(`These are flags which don't do anything in the current Miller version.
They are accepted as no-op flags in order to keep old scripts from breaking.`)
}
func init() { LegacyFlagSection.Sort() }
var LegacyFlagSection = FlagSection{
name: "Legacy flags",
infoPrinter: LegacyFlagInfoPrint,
flags: []Flag{
{
name: "--mmap",
help: "Miller no longer uses memory-mapping to access data files.",
parser: NoOpParse1,
},
{
name: "--no-mmap",
help: "Miller no longer uses memory-mapping to access data files.",
parser: NoOpParse1,
},
{
name: "--jsonx",
help: "The `--jvstack` flag is now default true in Miller 6.",
parser: NoOpParse1,
},
{
name: "--ojsonx",
help: "The `--jvstack` flag is now default true in Miller 6.",
parser: NoOpParse1,
},
{
name: "--jknquoteint",
help: "Type information from JSON input files is now preserved throughout the processing stream.",
parser: NoOpParse1,
},
{
name: "--jquoteall",
help: "Type information from JSON input files is now preserved throughout the processing stream.",
parser: NoOpParse1,
},
{
name: "--json-fatal-arrays-on-input",
help: "Miller now supports arrays as of version 6.",
parser: NoOpParse1,
},
{
name: "--json-map-arrays-on-input",
help: "Miller now supports arrays as of version 6.",
parser: NoOpParse1,
},
{
name: "--json-skip-arrays-on-input",
help: "Miller now supports arrays as of version 6.",
parser: NoOpParse1,
},
{
name: "--vflatsep",
help: "Ignored as of version 6. This functionality is subsumed into JSON formatting.",
parser: NoOpParse1,
},
{
name: "--quote-none",
help: "Ignored as of version 6. Types are inferred/retained through the processing flow now.",
parser: NoOpParse1,
},
{
name: "--quote-minimal",
help: "Ignored as of version 6. Types are inferred/retained through the processing flow now.",
parser: NoOpParse1,
},
{
name: "--quote-numeric",
help: "Ignored as of version 6. Types are inferred/retained through the processing flow now.",
parser: NoOpParse1,
},
{
name: "--quote-original",
help: "Ignored as of version 6. Types are inferred/retained through the processing flow now.",
parser: NoOpParse1,
},
},
}
// ================================================================
// FILE-FORMAT FLAGS
func FileFormatPrintInfo() {
fmt.Println(`See the File formats doc page, and or ` + "`mlr help file-formats`" + `, for more
about file formats Miller supports.
Examples: ` + "`--csv`" + ` for CSV-formatted input and output; ` + "`--icsv --opprint`" + ` for
CSV-formatted input and pretty-printed output.
Please use ` + "`--iformat1 --oformat2`" + ` rather than ` + "`--format1 --oformat2`" + `.
The latter sets up input and output flags for ` + "`format1`" + `, not all of which
are overridden in all cases by setting output format to ` + "`format2`" + `.`)
}
func init() { FileFormatFlagSection.Sort() }
var FileFormatFlagSection = FlagSection{
name: "File-format flags",
infoPrinter: FileFormatPrintInfo,
flags: []Flag{
{
name: "--icsv",
help: "Use CSV format for input data.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "csv"
*pargi += 1
},
},
{
name: "--icsvlite",
help: "Use CSV-lite format for input data.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "csvlite"
*pargi += 1
},
},
{
name: "--itsv",
help: "Use TSV format for input data.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "tsv"
*pargi += 1
},
},
{
name: "--itsvlite",
help: "Use TSV-lite format for input data.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "csvlite"
options.ReaderOptions.IFS = "\t"
options.ReaderOptions.ifsWasSpecified = true
*pargi += 1
},
},
{
name: "--iasv",
altNames: []string{"--iasvlite"},
help: "Use ASV format for input data.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "csvlite"
options.ReaderOptions.IFS = ASV_FS
options.ReaderOptions.IRS = ASV_RS
options.ReaderOptions.ifsWasSpecified = true
options.ReaderOptions.irsWasSpecified = true
*pargi += 1
},
},
{
name: "--iusv",
altNames: []string{"--iusvlite"},
help: "Use USV format for input data.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "csvlite"
options.ReaderOptions.IFS = USV_FS
options.ReaderOptions.IRS = USV_RS
options.ReaderOptions.ifsWasSpecified = true
options.ReaderOptions.irsWasSpecified = true
*pargi += 1
},
},
{
name: "--idkvp",
help: "Use DKVP format for input data.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "dkvp"
*pargi += 1
},
},
{
name: "--ijson",
help: "Use JSON format for input data.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "json"
*pargi += 1
},
},
{
name: "--ijsonl",
help: "Use JSON Lines format for input data.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "json"
*pargi += 1
},
},
{
name: "--inidx",
help: "Use NIDX format for input data.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "nidx"
*pargi += 1
},
},
{
name: "--ixtab",
help: "Use XTAB format for input data.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "xtab"
*pargi += 1
},
},
{
name: "--ipprint",
help: "Use PPRINT format for input data.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "pprint"
options.ReaderOptions.IFS = " "
options.ReaderOptions.ifsWasSpecified = true
*pargi += 1
},
},
{
name: "-i",
arg: "{format name}",
help: "Use format name for input data. For example: `-i csv` is the same as `--icsv`.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
CheckArgCount(args, *pargi, argc, 2)
options.ReaderOptions.InputFileFormat = args[*pargi+1]
if options.ReaderOptions.InputFileFormat == "md" {
options.ReaderOptions.InputFileFormat = "markdown" // alias
}
*pargi += 2
},
},
{
name: "--igen",
help: `Ignore input files and instead generate sequential numeric input using --gen-field-name,
--gen-start, --gen-step, and --gen-stop values. See also the seqgen verb, which is more useful/intuitive.`,
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "gen"
*pargi += 1
},
},
{
name: "--gen-field-name",
help: `Specify field name for --igen. Defaults to "` + DEFAULT_GEN_FIELD_NAME + `".`,
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "gen"
CheckArgCount(args, *pargi, argc, 2)
options.ReaderOptions.GeneratorOptions.FieldName = args[*pargi+1]
*pargi += 2
},
},
{
name: "--gen-start",
help: "Specify start value for --igen. Defaults to " + DEFAULT_GEN_START_AS_STRING + ".",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "gen"
CheckArgCount(args, *pargi, argc, 2)
options.ReaderOptions.GeneratorOptions.StartAsString = args[*pargi+1]
*pargi += 2
},
},
{
name: "--gen-step",
help: "Specify step value for --igen. Defaults to " + DEFAULT_GEN_STEP_AS_STRING + ".",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "gen"
CheckArgCount(args, *pargi, argc, 2)
options.ReaderOptions.GeneratorOptions.StepAsString = args[*pargi+1]
*pargi += 2
},
},
{
name: "--gen-stop",
help: "Specify stop value for --igen. Defaults to " + DEFAULT_GEN_STOP_AS_STRING + ".",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "gen"
CheckArgCount(args, *pargi, argc, 2)
options.ReaderOptions.GeneratorOptions.StopAsString = args[*pargi+1]
*pargi += 2
},
},
{
name: "-o",
arg: "{format name}",
help: "Use format name for output data. For example: `-o csv` is the same as `--ocsv`.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
CheckArgCount(args, *pargi, argc, 2)
options.WriterOptions.OutputFileFormat = args[*pargi+1]
if options.WriterOptions.OutputFileFormat == "md" {
options.WriterOptions.OutputFileFormat = "markdown" // alias
}
*pargi += 2
},
},
{
name: "--ocsv",
help: "Use CSV format for output data.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.WriterOptions.OutputFileFormat = "csv"
*pargi += 1
},
},
{
name: "--ocsvlite",
help: "Use CSV-lite format for output data.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.WriterOptions.OutputFileFormat = "csvlite"
*pargi += 1
},
},
{
name: "--otsv",
help: "Use TSV format for output data.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.WriterOptions.OutputFileFormat = "tsv"
options.WriterOptions.OFS = "\t"
options.WriterOptions.ofsWasSpecified = true
*pargi += 1
},
},
{
name: "--otsvlite",
help: "Use TSV-lite format for output data.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.WriterOptions.OutputFileFormat = "csvlite"
options.WriterOptions.OFS = "\t"
options.WriterOptions.ofsWasSpecified = true
*pargi += 1
},
},
{
name: "--oasv",
altNames: []string{"--oasvlite"},
help: "Use ASV format for output data.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.WriterOptions.OutputFileFormat = "csvlite"
options.WriterOptions.OFS = ASV_FS
options.WriterOptions.ORS = ASV_RS
options.WriterOptions.ofsWasSpecified = true
options.WriterOptions.orsWasSpecified = true
*pargi += 1
},
},
{
name: "--ousv",
altNames: []string{"--ousvlite"},
help: "Use USV format for output data.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.WriterOptions.OutputFileFormat = "csvlite"
options.WriterOptions.OFS = USV_FS
options.WriterOptions.ORS = USV_RS
options.WriterOptions.ofsWasSpecified = true
options.WriterOptions.orsWasSpecified = true
*pargi += 1
},
},
{
name: "--imd",
altNames: []string{"--imarkdown"},
help: "Use markdown-tabular format for input data.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "markdown"
*pargi += 1
},
},
{
name: "--omd",
altNames: []string{"--omarkdown"},
help: "Use markdown-tabular format for output data.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.WriterOptions.OutputFileFormat = "markdown"
*pargi += 1
},
},
{
name: "--odkvp",
help: "Use DKVP format for output data.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.WriterOptions.OutputFileFormat = "dkvp"
*pargi += 1
},
},
{
name: "--ojson",
help: "Use JSON format for output data.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.WriterOptions.OutputFileFormat = "json"
options.WriterOptions.WrapJSONOutputInOuterList = true
options.WriterOptions.JSONOutputMultiline = true
*pargi += 1
},
},
{
name: "--ojsonl",
help: "Use JSON Lines format for output data.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.WriterOptions.OutputFileFormat = "json"
options.WriterOptions.WrapJSONOutputInOuterList = false
options.WriterOptions.JSONOutputMultiline = false
*pargi += 1
},
},
{
name: "--onidx",
help: "Use NIDX format for output data.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.WriterOptions.OutputFileFormat = "nidx"
options.WriterOptions.OFS = " "
options.WriterOptions.ofsWasSpecified = true
*pargi += 1
},
},
{
name: "--oxtab",
help: "Use XTAB format for output data.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.WriterOptions.OutputFileFormat = "xtab"
*pargi += 1
},
},
{
name: "--opprint",
help: "Use PPRINT format for output data.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.WriterOptions.OutputFileFormat = "pprint"
*pargi += 1
},
},
{
name: "--io",
arg: "{format name}",
help: "Use format name for input and output data. For example: `--io csv` is the same as `--csv`.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
CheckArgCount(args, *pargi, argc, 2)
if defaultFSes[args[*pargi+1]] == "" {
fmt.Fprintf(os.Stderr, "mlr: unrecognized I/O format \"%s\".\n",
args[*pargi+1])