Skip to content

Commit 1d77814

Browse files
Cmd Options: -H for --header; --help-verbos (#12)
Two changes: (a) --help is short help, --help-verbose is detailed help. (b) -H is a shortcut for --header
1 parent 857b6f4 commit 1d77814

17 files changed

Lines changed: 192 additions & 85 deletions

File tree

README.md

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,9 @@ $ tsv-uniq --help # Valid
382382
$ tsv-uniq -help # Invalid.
383383
```
384384

385-
#### Help (-h, --help, --help-brief)
385+
#### Help (-h, --help, --help-verbose)
386386

387-
All tools print help if given the `-h` or `--help` option. Several tools provide a brief form of help with the `--help-brief` option.
387+
All tools print help if given the `-h` or `--help` option. Many of the tools provide more details with the `--help-verbose` option.
388388

389389
#### Field indices
390390

@@ -400,9 +400,9 @@ Any character can be used as a delimiter, TAB is the default. However, there is
400400

401401
Aside from a header line, all lines are expected to have data. There is no comment mechanism and no special handling for blank lines. Tools taking field indices as arguments expect the specified fields to be available on every line.
402402

403-
#### Headers (--header)
403+
#### Headers (-H, --header)
404404

405-
Most tools handle the first line of files as a header when given the `--header` option. For example, `tsv-filter` passes the header through without filtering it. When `--header` is used, all files and stdin are assumed to have header lines. Only one header line is written to stdout. If multiple files are being processed, header lines from subsequent files are discarded.
405+
Most tools handle the first line of files as a header when given the `-H` or `--header` option. For example, `tsv-filter` passes the header through without filtering it. When `--header` is used, all files and stdin are assumed to have header lines. Only one header line is written to stdout. If multiple files are being processed, header lines from subsequent files are discarded.
406406

407407
#### Multiple files and standard input
408408

@@ -421,8 +421,9 @@ Filter lines of tab-delimited files via comparison tests against fields. Multipl
421421

422422
**General options:**
423423
* `--help` - Print help.
424-
* `--help-brief` - Print brief help (option summary).
425-
* `--header` - Treat the first line of each file as a header.
424+
* `--help-verbose` - Print detailed help.
425+
* `--help-options` - Print the options list by itself.
426+
* `--H|header` - Treat the first line of each file as a header.
426427
* `--d|delimiter CHR` - Field delimiter. Default: TAB. (Single byte UTF-8 characters only.)
427428
* `--or` - Evaluate tests as an OR rather than an AND. This applies globally.
428429
* `--v|invert` - Invert the filter, printing lines that do not match. This applies globally.
@@ -524,18 +525,18 @@ $ tsv-filter --regex '2:\p{Cyrillic}' data.tsv
524525
tsv-join matches input lines against lines from a 'filter' file. The match is based on exact match comparison of one or more 'key' fields. Fields are TAB delimited by default. Matching lines are written to standard output, along with any additional fields from the key file that have been specified.
525526

526527
**Options:**
528+
* `--h|help` - Print help.
529+
* `--h|help-verbose` - Print detailed help.
527530
* `--f|filter-file FILE` - (Required) File with records to use as a filter.
528531
* `--k|key-fields n[,n...]` - Fields to use as join key. Default: 0 (entire line).
529532
* `--d|data-fields n[,n...]` - Data record fields to use as join key, if different than --key-fields.
530533
* `--a|append-fields n[,n...]` - Filter fields to append to matched records.
531-
* `--header` - Treat the first line of each file as a header.
534+
* `--H|header` - Treat the first line of each file as a header.
532535
* `--p|prefix STR` - String to use as a prefix for --append-fields when writing a header line.
533536
* `--w|write-all STR` - Output all data records. STR is the --append-fields value when writing unmatched records. This is an outer join.
534537
* `--e|exclude` - Exclude matching records. This is an anti-join.
535538
* `--delimiter CHR` - Field delimiter. Default: TAB. (Single byte UTF-8 characters only.)
536539
* `--z|allow-duplicate-keys` - Allow duplicate keys with different append values (last entry wins). Default behavior is that this is an error.
537-
* `--h|help` - Print help.
538-
* `--h|help-brief` - Print brief help.
539540

540541
**Examples:**
541542

@@ -582,15 +583,15 @@ The alternate to 'uniq' mode is 'equiv-class' identification. In this mode, all
582583
**Synopsis:** tsv-uniq [options] [file...]
583584

584585
**Options:**
585-
* `--header` - Treat the first line of each file as a header.
586+
* `-h|help` - Print help.
587+
* `--help-verbose` - Print detailed help.
588+
* `--H|header` - Treat the first line of each file as a header.
586589
* `--f|fields n[,n...]` - Fields to use as the key. Default: 0 (entire line).
587590
* `--i|ignore-case` - Ignore case when comparing keys.
588591
* `--e|equiv` - Output equiv class IDs rather than uniq'ing entries.
589592
* `--equiv-header STR` - Use STR as the equiv-id field header. Applies when using '--header --equiv'. Default: 'equiv_id'.
590593
* `--equiv-start INT` - Use INT as the first equiv-id. Default: 1.
591594
* `--d|delimiter CHR` - Field delimiter. Default: TAB. (Single byte UTF-8 characters only.)
592-
* `-h|help` - Print help.
593-
* `--help-brief` - Print brief help.
594595

595596
**Examples:**
596597
```
@@ -620,11 +621,11 @@ $ tsv-uniq -f 1,2 --equiv --header data.tsv
620621
tsv-select reads files or standard input and writes specified fields to standard output in the order listed. Similar to 'cut' with the ability to reorder fields. Fields can be listed more than once, and fields not listed can be output using the `--rest` option. When working with multiple files, the `--header` option can be used to retain only the header from the first file.
621622

622623
**Options:**
624+
* `--h|help` - Print help.
623625
* `--H|header` - Treat the first line of each file as a header.
624626
* `--f|fields n[,n...]` - (Required) Fields to extract. Fields are output in the order listed.
625627
* `--r|rest none|first|last` - Location for remaining fields. Default: none
626628
* `--d|delimiter CHR` - Character to use as field delimiter. Default: TAB. (Single byte UTF-8 characters only.)
627-
* `--h|help` - Print help.
628629

629630
**Examples:**
630631
```
@@ -693,8 +694,8 @@ Summarization operators available are:
693694
Calculations hold onto the minimum data needed while reading data. A few operations like median keep all data values in memory. These operations will start to encounter performance issues as available memory becomes scarce. The size that can be handled effectively is machine dependent, but often quite large files can be handled. Operations requiring numeric entries will signal an error and terminate processing if a non-numeric entry is found.
694695

695696
**Options:**
696-
* `--h|help` - Brief help.
697-
* `--help-verbose` - Print full help.
697+
* `--h|help` - Print help.
698+
* `--help-verbose` - Print detailed help.
698699
* `--g|group-by n[,n...]` - Fields to use as key.
699700
* `--H|header` - Treat the first line of each file as a header.
700701
* `--w|write-header` - Write an output header even if there is no input header.
@@ -746,12 +747,13 @@ This program does not validate CSV correctness, but will terminate with an error
746747
UTF-8 input is assumed. Convert other encodings prior to invoking this tool.
747748

748749
**Options:**
749-
* `--header` - Treat the first line of each file as a header. Only the header of the first file is output.
750+
* `--h|help` - Print help.
751+
* `--help-verbose` - Print detailed help.
752+
* `--H|header` - Treat the first line of each file as a header. Only the header of the first file is output.
750753
* `--q|quote CHR` - Quoting character in CSV data. Default: double-quote (")
751754
* `--c|csv-delim CHR` - Field delimiter in CSV data. Default: comma (,).
752755
* `--t|tsv-delim CHR` - Field delimiter in TSV data. Default: TAB
753756
* `--r|replacement STR` - Replacement for newline and TSV field delimiters found in CSV input. Default: Space.
754-
* `--h|help` - Print help.
755757

756758
### number-lines reference
757759

@@ -760,11 +762,11 @@ UTF-8 input is assumed. Convert other encodings prior to invoking this tool.
760762
number-lines reads from files or standard input and writes each line to standard output preceded by a line number. It is a simplified version of the Unix 'nl' program. It supports one feature 'nl' does not: the ability to treat the first line of files as a header. This is useful when working with tab-separated-value files. If header processing used, a header line is written for the first file, and the header lines are dropped from any subsequent files.
761763

762764
**Options:**
763-
* `--header` - Treat the first line of each file as a header. The first input file's header is output, subsequent file headers are discarded.
765+
* `--h|help` - Print help.
766+
* `--H|header` - Treat the first line of each file as a header. The first input file's header is output, subsequent file headers are discarded.
764767
* `--s|header-string STR` - String to use as the header for the line number field. Implies --header. Default: 'line'.
765768
* `--n|start-number NUM` - Number to use for the first line. Default: 1.
766769
* `--d|delimiter CHR` - Character appended to line number, preceding the rest of the line. Default: TAB (Single byte UTF-8 characters only.)
767-
* `--h|help` - Print help.
768770

769771
**Examples:**
770772
```

csv2tsv/src/csv2tsv.d

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ import std.typecons : Nullable, tuple;
1818
auto helpText = q"EOS
1919
Synopsis: csv2tsv [options] [file...]
2020
21+
csv2tsv converts comma-separated text (CSV) to tab-separated format (TSV). Records
22+
are read from files or standard input, converted records written to standard output.
23+
Use '--help-verbose' for details the CSV formats accepted.
24+
25+
Options:
26+
EOS";
27+
28+
auto helpTextVerbose = q"EOS
29+
Synopsis: csv2tsv [options] [file...]
30+
2131
csv2tsv converts CSV (comma-separated) text to TSV (tab-separated) format. Records
2232
are read from files or standard input, converted records written to standard output.
2333
@@ -58,6 +68,7 @@ EOS";
5868
Container for command line options.
5969
*/
6070
struct Csv2tsvOptions {
71+
bool helpVerbose = false; // --help-verbose
6172
bool hasHeader = false; // --header
6273
char csvQuoteChar = '"'; // --q|quote
6374
char csvDelimChar = ','; // --c|csv-delim
@@ -71,7 +82,10 @@ struct Csv2tsvOptions {
7182
try {
7283
auto r = getopt(
7384
cmdArgs,
74-
"header", " Treat the first line of each file as a header. Only the header of the first file is output.", &hasHeader,
85+
"help-verbose", " Print full help.", &helpVerbose,
86+
std.getopt.config.caseSensitive,
87+
"H|header", " Treat the first line of each file as a header. Only the header of the first file is output.", &hasHeader,
88+
std.getopt.config.caseSensitive,
7589
"q|quote", "CHR Quoting character in CSV data. Default: double-quote (\")", &csvQuoteChar,
7690
"c|csv-delim", "CHR Field delimiter in CSV data. Default: comma (,).", &csvDelimChar,
7791
"t|tsv-delim", "CHR Field delimiter in TSV data. Default: TAB", &tsvDelimChar,
@@ -81,6 +95,9 @@ struct Csv2tsvOptions {
8195
if (r.helpWanted) {
8296
defaultGetoptPrinter(helpText, r.options);
8397
return tuple(false, 0);
98+
} else if (helpVerbose) {
99+
defaultGetoptPrinter(helpTextVerbose, r.options);
100+
return tuple(false, 0);
84101
}
85102

86103
/* Consistency checks. */

csv2tsv/tests/gold/basic_tests_1.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ jkl mno pqr
119119
ABC DEF GHI
120120
JKL MNO PQR
121121

122+
====[csv2tsv -H header1.csv header2.csv header3.csv header4.csv header5.csv]====
123+
field1 field2 field3
124+
123 456 789
125+
234 567 890
126+
345 678 901
127+
abc def ghi
128+
jkl mno pqr
129+
ABC DEF GHI
130+
JKL MNO PQR
131+
122132
====[cat header3.csv | csv2tsv --header -- header1.csv header2.csv - header4.csv header5.csv]====
123133
field1 field2 field3
124134
123 456 789

csv2tsv/tests/tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ runtest ${prog} "--quote # --csv-delim | --tsv-delim $ --replacement <==> input2
3333
runtest ${prog} "-q # -c | -t @ -r <--> input2.csv" ${basic_tests_1}
3434
runtest ${prog} "header1.csv header2.csv header3.csv header4.csv header5.csv" ${basic_tests_1}
3535
runtest ${prog} "--header header1.csv header2.csv header3.csv header4.csv header5.csv" ${basic_tests_1}
36+
runtest ${prog} "-H header1.csv header2.csv header3.csv header4.csv header5.csv" ${basic_tests_1}
3637

3738
echo "" >> ${basic_tests_1}; echo "====[cat header3.csv | csv2tsv --header -- header1.csv header2.csv - header4.csv header5.csv]====" >> ${basic_tests_1}
3839
cat header3.csv | ${prog} --header -- header1.csv header2.csv - header4.csv header5.csv >> ${basic_tests_1} 2>&1

number-lines/src/number-lines.d

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ struct NumberLinesOptions {
5454
try {
5555
auto r = getopt(
5656
cmdArgs,
57-
"header", " Treat the first line of each file as a header. The first input file's header is output, subsequent file headers are discarded.", &hasHeader,
57+
std.getopt.config.caseSensitive,
58+
"H|header", " Treat the first line of each file as a header. The first input file's header is output, subsequent file headers are discarded.", &hasHeader,
59+
std.getopt.config.caseInsensitive,
5860
"s|header-string", "STR String to use in the header row. Implies --header. Default: 'line'", &headerString,
5961
"n|start-number", "NUM Number to use for the first line. Default: 1", &startNum,
6062
"d|delimiter", "CHR Character appended to line number, preceding the rest of the line. Default: TAB (Single byte UTF-8 characters only.)", &delim

number-lines/tests/gold/basic_tests_1.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,15 @@ line^The first line - Is it a header?
163163
19
164164
20 Previous line a single tab
165165

166+
====[number-lines -H input2.txt input2.txt input2.txt]====
167+
line The first line
168+
1 The second line
169+
2 The third line
170+
3 The second line
171+
4 The third line
172+
5 The second line
173+
6 The third line
174+
166175
====[number-lines --header input1.txt input2.txt empty-file.txt one-line-file.txt]====
167176
line The first line - Is it a header?
168177
1 abc def ghi

number-lines/tests/tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ echo "" >> ${basic_tests_1}; echo "====Multi-file Tests===" >> ${basic_tests_1}
3939
runtest ${prog} "input1.txt input2.txt empty-file.txt one-line-file.txt" ${basic_tests_1}
4040
runtest ${prog} "input1.txt one-line-file.txt input2.txt empty-file.txt" ${basic_tests_1}
4141
runtest ${prog} "empty-file.txt input1.txt one-line-file.txt input2.txt input1.txt" ${basic_tests_1}
42+
runtest ${prog} "-H input2.txt input2.txt input2.txt" ${basic_tests_1}
4243
runtest ${prog} "--header input1.txt input2.txt empty-file.txt one-line-file.txt" ${basic_tests_1}
4344
runtest ${prog} "--header -n 10 input1.txt one-line-file.txt input2.txt empty-file.txt" ${basic_tests_1}
4445
runtest ${prog} "--header -s LINENUM empty-file.txt input1.txt one-line-file.txt input2.txt input1.txt" ${basic_tests_1}

0 commit comments

Comments
 (0)