i think argparse is done
parent
8902e17b40
commit
ecd3d1a701
|
@ -1,6 +1,6 @@
|
||||||
cmake_minimum_required(VERSION 3.20)
|
cmake_minimum_required(VERSION 3.20)
|
||||||
include(cmake/color.cmake)
|
include(cmake/color.cmake)
|
||||||
set(BLT_VERSION 4.0.36)
|
set(BLT_VERSION 4.0.37)
|
||||||
|
|
||||||
set(BLT_TARGET BLT)
|
set(BLT_TARGET BLT)
|
||||||
|
|
||||||
|
|
|
@ -623,7 +623,7 @@ namespace blt::argparse
|
||||||
|
|
||||||
argument_parser_t& with_help()
|
argument_parser_t& with_help()
|
||||||
{
|
{
|
||||||
add_flag("--help", "-h").set_action(action_t::HELP);
|
add_flag("--help", "-h").set_action(action_t::HELP).set_help("Show this help menu and exit");
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -405,20 +405,86 @@ namespace blt::argparse
|
||||||
help.newline();
|
help.newline();
|
||||||
for (const auto& [key, value] : m_subparsers)
|
for (const auto& [key, value] : m_subparsers)
|
||||||
{
|
{
|
||||||
help += '\t';
|
|
||||||
auto map = value.get_allowed_strings();
|
auto map = value.get_allowed_strings();
|
||||||
// TODO: make an unzip?
|
help += '\t';
|
||||||
for (const auto& [parser, strings] : map)
|
help += key;
|
||||||
|
help += ": {";
|
||||||
|
for (const auto& [i, parser, strings] : enumerate(map).flatten())
|
||||||
{
|
{
|
||||||
|
if (strings.size() > 1)
|
||||||
|
help += '[';
|
||||||
for (const auto& [i, str] : enumerate(strings))
|
for (const auto& [i, str] : enumerate(strings))
|
||||||
{
|
{
|
||||||
help += str;
|
help += str;
|
||||||
if (i != strings.size() - 1)
|
if (i != strings.size() - 1)
|
||||||
help += ", ";
|
help += ", ";
|
||||||
}
|
}
|
||||||
// help += parser.he
|
if (strings.size() > 1)
|
||||||
help.newline();
|
help += ']';
|
||||||
|
if (i != map.size() - 1)
|
||||||
|
help += ", ";
|
||||||
}
|
}
|
||||||
|
help += "}";
|
||||||
|
help.newline();
|
||||||
|
}
|
||||||
|
help.newline();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_positional_arguments.empty())
|
||||||
|
{
|
||||||
|
help += "Positional Arguments:";
|
||||||
|
help.newline();
|
||||||
|
for (auto& [name, builder] : m_positional_arguments)
|
||||||
|
{
|
||||||
|
help += '\t';
|
||||||
|
if (!builder.m_required)
|
||||||
|
help += '[';
|
||||||
|
help += name;
|
||||||
|
if (!builder.m_required)
|
||||||
|
help += ']';
|
||||||
|
if (builder.m_default_value && !(builder.m_action == action_t::STORE_TRUE || builder.m_action == action_t::STORE_FALSE))
|
||||||
|
{
|
||||||
|
if (!std::isblank(help.str().back()))
|
||||||
|
help += " ";
|
||||||
|
help += "(Default: ";
|
||||||
|
std::visit(detail::arg_meta_type_helper_t::make_visitor(
|
||||||
|
[&](auto& value)
|
||||||
|
{
|
||||||
|
help += value;
|
||||||
|
},
|
||||||
|
[&](auto& vec)
|
||||||
|
{
|
||||||
|
if constexpr (!std::is_same_v<std::decay_t<meta::remove_cvref_t<decltype(vec)>>, std::vector<bool>>)
|
||||||
|
{
|
||||||
|
help += '[';
|
||||||
|
for (const auto& [i, v] : enumerate(vec))
|
||||||
|
{
|
||||||
|
help += v;
|
||||||
|
if (i != vec.size() - 1)
|
||||||
|
help += ", ";
|
||||||
|
}
|
||||||
|
help += ']';
|
||||||
|
}
|
||||||
|
}), *builder.m_default_value);
|
||||||
|
help += ")";
|
||||||
|
}
|
||||||
|
if (builder.m_choices)
|
||||||
|
{
|
||||||
|
if (!std::isblank(help.str().back()))
|
||||||
|
help += " ";
|
||||||
|
help += "(Choices: ";
|
||||||
|
for (const auto& [i, v] : enumerate(*builder.m_choices))
|
||||||
|
{
|
||||||
|
help += '\'';
|
||||||
|
help += v;
|
||||||
|
help += '\'';
|
||||||
|
if (i != builder.m_choices->size() - 1)
|
||||||
|
help += ", ";
|
||||||
|
}
|
||||||
|
help += ')';
|
||||||
|
}
|
||||||
|
help.newline();
|
||||||
|
help.newline();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -514,12 +580,20 @@ namespace blt::argparse
|
||||||
str += "(Choices: ";
|
str += "(Choices: ";
|
||||||
for (const auto& [i, v] : enumerate(*builder->m_choices))
|
for (const auto& [i, v] : enumerate(*builder->m_choices))
|
||||||
{
|
{
|
||||||
|
str += '\'';
|
||||||
str += v;
|
str += v;
|
||||||
|
str += '\'';
|
||||||
if (i != builder->m_choices->size() - 1)
|
if (i != builder->m_choices->size() - 1)
|
||||||
str += ", ";
|
str += ", ";
|
||||||
}
|
}
|
||||||
str += ')';
|
str += ')';
|
||||||
}
|
}
|
||||||
|
if (builder->m_required)
|
||||||
|
{
|
||||||
|
if (!std::isblank(str.str().back()))
|
||||||
|
str += " ";
|
||||||
|
str += "(Required)";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -545,6 +619,14 @@ namespace blt::argparse
|
||||||
parent = parent->m_parent->m_parent;
|
parent = parent->m_parent->m_parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const auto& [key, _] : m_subparsers)
|
||||||
|
{
|
||||||
|
aligner += '{';
|
||||||
|
aligner += key;
|
||||||
|
aligner += '}';
|
||||||
|
aligner += ' ';
|
||||||
|
}
|
||||||
|
|
||||||
hashmap_t<std::string, std::vector<std::string>> singleFlags;
|
hashmap_t<std::string, std::vector<std::string>> singleFlags;
|
||||||
std::vector<std::pair<argument_string_t, argument_builder_t*>> compoundFlags;
|
std::vector<std::pair<argument_string_t, argument_builder_t*>> compoundFlags;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue