Add usage in OptionParser.
GitOrigin-RevId: 0a15b69eda345c0fbc503afc26c6787f5fbcaa8e
This commit is contained in:
parent
6e08881d81
commit
0ad6ff0599
@ -7,12 +7,18 @@
|
||||
#include "td/utils/OptionParser.h"
|
||||
|
||||
#include "td/utils/logging.h"
|
||||
#include "td/utils/PathView.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace td {
|
||||
|
||||
void OptionParser::set_usage(Slice executable_name, Slice usage) {
|
||||
PathView path_view(executable_name);
|
||||
usage_ = PSTRING() << path_view.file_name() << " " << usage;
|
||||
}
|
||||
|
||||
void OptionParser::set_description(string description) {
|
||||
description_ = std::move(description);
|
||||
}
|
||||
@ -170,6 +176,9 @@ Result<vector<char *>> OptionParser::run(int argc, char *argv[], int expected_no
|
||||
}
|
||||
|
||||
StringBuilder &operator<<(StringBuilder &sb, const OptionParser &o) {
|
||||
if (!o.usage_.empty()) {
|
||||
sb << "Usage: " << o.usage_ << "\n\n";
|
||||
}
|
||||
if (!o.description_.empty()) {
|
||||
sb << o.description_ << ". ";
|
||||
}
|
||||
|
@ -45,6 +45,8 @@ class OptionParser {
|
||||
};
|
||||
}
|
||||
|
||||
void set_usage(Slice executable_name, Slice usage);
|
||||
|
||||
void set_description(string description);
|
||||
|
||||
void add_checked_option(char short_key, Slice long_key, Slice description, std::function<Status(Slice)> callback);
|
||||
@ -69,6 +71,7 @@ class OptionParser {
|
||||
private:
|
||||
vector<Option> options_;
|
||||
vector<std::function<Status()>> checks_;
|
||||
string usage_;
|
||||
string description_;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user