Skip to content

Commit 46c9ea8

Browse files
committed
Now we can pass an bool value as options to commandLineParser.
1 parent cb17108 commit 46c9ea8

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

core/base/common/CommandLineParser.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ namespace ttk {
162162
arguments_[j].doubleValueList_->size() + 1);
163163
s >> arguments_[j].doubleValueList_->back();
164164
arguments_[j].isSet_ = true;
165+
} else if(arguments_[j].boolValue_) {
166+
std::stringstream s(argv[i + 1]);
167+
s >> *(arguments_[j].boolValue_);
168+
arguments_[j].isSet_ = true;
165169
}
166170
}
167171
} else {
@@ -257,6 +261,12 @@ namespace ttk {
257261
s += " ";
258262
}
259263
}
264+
} else if(arguments_[i].boolValue_) {
265+
if(!arguments_[i].isSet_) {
266+
s += "(not set)";
267+
} else {
268+
s += std::to_string(*(arguments_[i].boolValue_));
269+
}
260270
}
261271

262272
printMsg(s, debug::Priority::INFO, debug::LineMode::NEW, o);
@@ -310,6 +320,23 @@ namespace ttk {
310320
return 0;
311321
}
312322

323+
inline int setArgument(const std::string &key,
324+
bool *value,
325+
const std::string &description = "",
326+
const bool &optional = false) {
327+
328+
if(!value)
329+
return -1;
330+
331+
arguments_.resize(arguments_.size() + 1);
332+
arguments_.back().isOptional_ = optional;
333+
arguments_.back().key_ = key;
334+
arguments_.back().description_ = description;
335+
arguments_.back().boolValue_ = value;
336+
arguments_.back().isAnOption_ = false;
337+
338+
return 0;
339+
}
313340
int setArgument(const std::string &key,
314341
double *value,
315342
const std::string &description = "",

0 commit comments

Comments
 (0)