mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-04 15:14:39 +00:00
Sort names on argument construction
This commit is contained in:
parent
7c5ee10205
commit
34d259d892
@ -84,7 +84,11 @@ public:
|
|||||||
explicit Argument(Args... args)
|
explicit Argument(Args... args)
|
||||||
: mNames({std::move(args)...})
|
: mNames({std::move(args)...})
|
||||||
, mIsOptional((is_optional(args) || ...))
|
, mIsOptional((is_optional(args) || ...))
|
||||||
{}
|
{
|
||||||
|
std::sort(mNames.begin(), mNames.end(), [](const auto& lhs, const auto& rhs) {
|
||||||
|
return lhs.size() == rhs.size() ? lhs < rhs : lhs.size() < rhs.size();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Argument& help(std::string aHelp) {
|
Argument& help(std::string aHelp) {
|
||||||
mHelp = std::move(aHelp);
|
mHelp = std::move(aHelp);
|
||||||
@ -401,10 +405,6 @@ class ArgumentParser {
|
|||||||
for (const auto & mOptionalArgument : mOptionalArguments) {
|
for (const auto & mOptionalArgument : mOptionalArguments) {
|
||||||
size_t tCurrentLength = 0;
|
size_t tCurrentLength = 0;
|
||||||
auto tNames = mOptionalArgument->mNames;
|
auto tNames = mOptionalArgument->mNames;
|
||||||
std::sort(tNames.begin(), tNames.end(),
|
|
||||||
[](const std::string& lhs, const std::string& rhs) {
|
|
||||||
return lhs.size() == rhs.size() ? lhs < rhs : lhs.size() < rhs.size();
|
|
||||||
});
|
|
||||||
for (size_t j = 0; j < tNames.size() - 1; j++) {
|
for (size_t j = 0; j < tNames.size() - 1; j++) {
|
||||||
auto tCurrentName = tNames[j];
|
auto tCurrentName = tNames[j];
|
||||||
stream << tCurrentName;
|
stream << tCurrentName;
|
||||||
|
Loading…
Reference in New Issue
Block a user