mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-03 22:54:39 +00:00
Updated help to print subcommands list
This commit is contained in:
parent
2f2858a8a7
commit
6987a83ad5
@ -1113,11 +1113,15 @@ public:
|
||||
-> std::ostream & {
|
||||
stream.setf(std::ios_base::left);
|
||||
stream << "Usage: " << parser.m_program_name << " [options] ";
|
||||
std::size_t longest_arg_length = parser.get_length_of_longest_argument();
|
||||
|
||||
for (const auto &argument : parser.m_positional_arguments) {
|
||||
stream << argument.m_names.front() << " ";
|
||||
}
|
||||
|
||||
if (!parser.m_subparser_map.empty()) {
|
||||
stream << (parser.m_positional_arguments.empty() ? "" : " ")
|
||||
<< "<command> [<args>]";
|
||||
}
|
||||
std::size_t longest_arg_length = parser.get_length_of_longest_argument();
|
||||
stream << "\n\n";
|
||||
|
||||
if (!parser.m_description.empty()) {
|
||||
@ -1143,6 +1147,25 @@ public:
|
||||
stream << argument;
|
||||
}
|
||||
|
||||
if (!parser.m_subparser_map.empty()) {
|
||||
stream << (parser.m_positional_arguments.empty() ?
|
||||
(parser.m_optional_arguments.empty() ? "" : "\n") :
|
||||
"\n")
|
||||
<< "Subcommands:\n";
|
||||
stream << "{";
|
||||
std::size_t i = 0;
|
||||
for (const auto &[argument, unused] : parser.m_subparser_map) {
|
||||
if (i == 0) {
|
||||
stream << argument;
|
||||
}
|
||||
else {
|
||||
stream << ", " << argument;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
stream << "}\n";
|
||||
}
|
||||
|
||||
if (!parser.m_epilog.empty()) {
|
||||
stream << '\n';
|
||||
stream << parser.m_epilog << "\n\n";
|
||||
@ -1243,6 +1266,9 @@ private:
|
||||
for ([[maybe_unused]] const auto& [unused, argument] : m_argument_map) {
|
||||
max_size = std::max(max_size, argument->get_arguments_length());
|
||||
}
|
||||
for ([[maybe_unused]] const auto& [command, unused] : m_subparser_map) {
|
||||
max_size = std::max(max_size, command.size());
|
||||
}
|
||||
return max_size;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user