使help中的选项按添加顺序输出
This commit is contained in:
@@ -47,6 +47,8 @@ namespace ling {
|
|||||||
|
|
||||||
//预定义参数规则
|
//预定义参数规则
|
||||||
std::unordered_map<std::string, DataStruct> data;
|
std::unordered_map<std::string, DataStruct> data;
|
||||||
|
//用来生成帮助的数据
|
||||||
|
std::vector<DataStruct> helpData;
|
||||||
//匿名参数数量
|
//匿名参数数量
|
||||||
int anonymityNumber = 0;
|
int anonymityNumber = 0;
|
||||||
int nextID = 1;
|
int nextID = 1;
|
||||||
@@ -83,7 +85,7 @@ namespace ling {
|
|||||||
const std::string &getError() const;
|
const std::string &getError() const;
|
||||||
|
|
||||||
/// 生成help内容
|
/// 生成help内容
|
||||||
std::string generateHelp(const std::string & title) const;
|
std::string generateHelp(const std::string &title) const;
|
||||||
|
|
||||||
friend class Options;
|
friend class Options;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ namespace ling {
|
|||||||
const int id = nextID++;
|
const int id = nextID++;
|
||||||
for (const auto &in: opt)
|
for (const auto &in: opt)
|
||||||
data[in] = DataStruct(opt, id, type, message);
|
data[in] = DataStruct(opt, id, type, message);
|
||||||
|
helpData.emplace_back(opt, id, type, message);
|
||||||
if (type == OPT)
|
if (type == OPT)
|
||||||
options[id] = false;
|
options[id] = false;
|
||||||
return {id, this};
|
return {id, this};
|
||||||
@@ -152,18 +152,18 @@ namespace ling {
|
|||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
stream << title << std::endl;
|
stream << title << std::endl;
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
for (const auto &[fst, snd]: data) {
|
for (const auto &in: helpData) {
|
||||||
std::stringstream temp;
|
std::stringstream temp;
|
||||||
//即使参数有多个选项,也只输出前两个
|
//即使参数有多个选项,也只输出前两个
|
||||||
if (snd.options.size() == 2) {
|
if (in.options.size() == 2) {
|
||||||
temp << std::left << std::setw(7) << (snd.options[0] + ",") << std::left << std::setw(18) << snd.options[1];
|
temp << std::left << std::setw(7) << (in.options[0] + ",") << std::left << std::setw(18) << in.options[1];
|
||||||
} else {
|
} else {
|
||||||
if (snd.options[0].at(0) == '-' && snd.options[0].at(1) == '-')
|
if (in.options[0].at(0) == '-' && in.options[0].at(1) == '-')
|
||||||
temp << std::left << std::setw(7) << "" << std::left << std::setw(18) << snd.options[0];
|
temp << std::left << std::setw(7) << "" << std::left << std::setw(18) << in.options[0];
|
||||||
else
|
else
|
||||||
temp << std::left << std::setw(25) << snd.options[0];
|
temp << std::left << std::setw(25) << in.options[0];
|
||||||
}
|
}
|
||||||
temp << std::left << std::setw(55) << snd.memage;
|
temp << std::left << std::setw(55) << in.memage;
|
||||||
stream << temp.str() << std::endl;
|
stream << temp.str() << std::endl;
|
||||||
}
|
}
|
||||||
return stream.str();
|
return stream.str();
|
||||||
|
|||||||
Reference in New Issue
Block a user