Skip to content

Commit 8074c58

Browse files
author
Matt Godbolt
committed
Add --tab-delimiter option. See #26
1 parent 713a7fa commit 8074c58

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/zindex.cpp

+18-7
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,12 @@ int Main(int argc, const char *argv[]) {
5757
false, 0, "num", cmd);
5858
ValueArg<string> configFile("c", "config", "Create indexes using json "
5959
"config file <file>", false, "", "indexes", cmd);
60-
ValueArg<string> delimiter("d", "delimiter",
61-
"Use <delim> as the field delimiter", false, " ",
62-
"delim", cmd);
60+
ValueArg<string> delimiterArg(
61+
"d", "delimiter", "Use <delim> as the field delimiter", false, " ",
62+
"delim", cmd);
63+
SwitchArg tabDelimiterArg(
64+
"", "tab-delimiter", "Use a tab character as the field delimiter",
65+
cmd);
6366
ValueArg<string> externalIndexer(
6467
"p", "pipe",
6568
"Create indices by piping output through <CMD> which should output "
@@ -99,12 +102,20 @@ int Main(int argc, const char *argv[]) {
99102
if (skipFirst.isSet())
100103
builder.skipFirst(skipFirst.getValue());
101104

102-
Index::IndexConfig config{ };
105+
Index::IndexConfig config{};
103106
config.numeric = numeric.isSet();
104107
config.unique = unique.isSet();
105108
config.sparse = sparse.isSet();
106109
//config.indexLineOffsets = // TODO - add command line flag if desired
107110

111+
auto delimiter = delimiterArg.getValue();
112+
if (tabDelimiterArg.isSet() && delimiterArg.isSet()) {
113+
log.error("Cannot set both --delimiter and --tab-delimiter");
114+
return 1;
115+
}
116+
if (tabDelimiterArg.isSet())
117+
delimiter = "\t";
118+
108119
if (configFile.isSet()) {
109120
auto indexParser = IndexParser(configFile.getValue());
110121
indexParser.buildIndexes(&builder, log);
@@ -123,18 +134,18 @@ int Main(int argc, const char *argv[]) {
123134
if (field.isSet()) {
124135
ostringstream name;
125136
name << "Field " << field.getValue() << " delimited by '"
126-
<< delimiter.getValue() << "'";
137+
<< delimiter << "'";
127138
builder.addIndexer("default", name.str(), config,
128139
std::unique_ptr<LineIndexer>(
129140
new FieldIndexer(
130-
delimiter.getValue(),
141+
delimiter,
131142
field.getValue())));
132143
}
133144
if (externalIndexer.isSet()) {
134145
auto indexer = std::unique_ptr<LineIndexer>(
135146
new ExternalIndexer(log,
136147
externalIndexer.getValue(),
137-
delimiter.getValue()));
148+
delimiter));
138149
builder.addIndexer("default", externalIndexer.getValue(),
139150
config, std::move(indexer));
140151
}

0 commit comments

Comments
 (0)