Remove unsupported OptionsParser::Option::Type::OptionalArg.
GitOrigin-RevId: 3226257bf95366472c843cce0e4ca76d3f3cee5c
This commit is contained in:
parent
bd207a2d19
commit
4bb6fe7e78
@ -17,7 +17,7 @@
|
||||
|
||||
namespace td {
|
||||
|
||||
void OptionsParser::set_description(std::string description) {
|
||||
void OptionsParser::set_description(string description) {
|
||||
description_ = std::move(description);
|
||||
}
|
||||
|
||||
@ -44,7 +44,6 @@ Result<int> OptionsParser::run(int argc, char *argv[]) {
|
||||
char buff[1024];
|
||||
StringBuilder sb(MutableSlice{buff, sizeof(buff)});
|
||||
for (auto &opt : options_) {
|
||||
CHECK(opt.type != Option::Type::OptionalArg);
|
||||
sb << opt.short_key;
|
||||
if (opt.type == Option::Type::Arg) {
|
||||
sb << ":";
|
||||
@ -112,15 +111,9 @@ StringBuilder &operator<<(StringBuilder &sb, const OptionsParser &o) {
|
||||
if (!opt.long_key.empty()) {
|
||||
sb << "|--" << opt.long_key;
|
||||
}
|
||||
if (opt.type == OptionsParser::Option::Type::OptionalArg) {
|
||||
sb << "[";
|
||||
}
|
||||
if (opt.type != OptionsParser::Option::Type::NoArg) {
|
||||
sb << "<arg>";
|
||||
}
|
||||
if (opt.type == OptionsParser::Option::Type::OptionalArg) {
|
||||
sb << "]";
|
||||
}
|
||||
sb << "\t" << opt.description;
|
||||
sb << "\n";
|
||||
}
|
||||
|
@ -18,20 +18,20 @@ namespace td {
|
||||
class OptionsParser {
|
||||
class Option {
|
||||
public:
|
||||
enum class Type { NoArg, Arg, OptionalArg };
|
||||
enum class Type { NoArg, Arg };
|
||||
Type type;
|
||||
char short_key;
|
||||
std::string long_key;
|
||||
std::string description;
|
||||
string long_key;
|
||||
string description;
|
||||
std::function<Status(Slice)> arg_callback;
|
||||
};
|
||||
|
||||
public:
|
||||
void set_description(std::string description);
|
||||
|
||||
void add_option(Option::Type type, char short_key, Slice long_key, Slice description,
|
||||
std::function<Status(Slice)> callback);
|
||||
|
||||
public:
|
||||
void set_description(string description);
|
||||
|
||||
void add_option(char short_key, Slice long_key, Slice description, std::function<Status(Slice)> callback);
|
||||
|
||||
void add_option(char short_key, Slice long_key, Slice description, std::function<Status(void)> callback);
|
||||
@ -41,8 +41,8 @@ class OptionsParser {
|
||||
friend StringBuilder &operator<<(StringBuilder &sb, const OptionsParser &o);
|
||||
|
||||
private:
|
||||
std::vector<Option> options_;
|
||||
std::string description_;
|
||||
vector<Option> options_;
|
||||
string description_;
|
||||
};
|
||||
|
||||
} // namespace td
|
||||
|
Loading…
x
Reference in New Issue
Block a user