mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-03 22:54:39 +00:00
subparser: use full parser path instead of just parser name in usage() message
This commit is contained in:
parent
b5cfa7ea46
commit
097bac1854
@ -2067,7 +2067,7 @@ public:
|
|||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
|
|
||||||
std::string curline("Usage: ");
|
std::string curline("Usage: ");
|
||||||
curline += this->m_program_name;
|
curline += this->m_parser_path;
|
||||||
const bool multiline_usage =
|
const bool multiline_usage =
|
||||||
this->m_usage_max_line_width < (std::numeric_limits<std::size_t>::max)();
|
this->m_usage_max_line_width < (std::numeric_limits<std::size_t>::max)();
|
||||||
const size_t indent_size = curline.size();
|
const size_t indent_size = curline.size();
|
||||||
|
@ -280,3 +280,29 @@ TEST_CASE("Check set_suppress" * test_suite("subparsers")) {
|
|||||||
REQUIRE(contains(program.help().str(), "command_2") == true);
|
REQUIRE(contains(program.help().str(), "command_2") == true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST_CASE("Help of subparsers" * test_suite("subparsers")) {
|
||||||
|
argparse::ArgumentParser program("test");
|
||||||
|
|
||||||
|
argparse::ArgumentParser command_1("add", "1.0", argparse::default_arguments::version);
|
||||||
|
|
||||||
|
std::stringstream buffer;
|
||||||
|
command_1.add_argument("--help")
|
||||||
|
.action([&](const auto &) { buffer << command_1; })
|
||||||
|
.default_value(false)
|
||||||
|
.implicit_value(true)
|
||||||
|
.nargs(0);
|
||||||
|
|
||||||
|
program.add_subparser(command_1);
|
||||||
|
|
||||||
|
REQUIRE(command_1.usage() == "Usage: test add [--version] [--help]");
|
||||||
|
|
||||||
|
REQUIRE(buffer.str().empty());
|
||||||
|
program.parse_args({"test", "add", "--help"});
|
||||||
|
REQUIRE(buffer.str() == "Usage: test add [--version] [--help]\n"
|
||||||
|
"\n"
|
||||||
|
"Optional arguments:\n"
|
||||||
|
" -v, --version prints version information and exits \n"
|
||||||
|
" --help \n");
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user