get_subcommand_no_throw (#1016)

get_subcommand when used for parsing config files, was throwing and
catching as part of control flow and expected operation, this resulting
in a performance hit in select cases. A get_subcommand_no_throw was
added to resolve this issue.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Philip Top
2024-03-12 09:45:17 -07:00
committed by GitHub
parent c04c9b2252
commit 6cd171ad3f
3 changed files with 19 additions and 12 deletions

View File

@@ -16,8 +16,10 @@ TEST_CASE_METHOD(TApp, "BasicSubcommands", "[subcom]") {
CHECK(app.get_subcommand(sub1) == sub1);
CHECK(app.get_subcommand("sub1") == sub1);
CHECK(app.get_subcommand_no_throw("sub1") == sub1);
CHECK_THROWS_AS(app.get_subcommand("sub3"), CLI::OptionNotFound);
CHECK_NOTHROW(app.get_subcommand_no_throw("sub3"));
CHECK(app.get_subcommand_no_throw("sub3") == nullptr);
run();
CHECK(app.get_subcommands().empty());
@@ -90,7 +92,7 @@ TEST_CASE_METHOD(TApp, "MultiSubFallthrough", "[subcom]") {
CHECK(!sub2->parsed());
CHECK(0u == sub2->count());
CHECK_THROWS_AS(app.got_subcommand("sub3"), CLI::OptionNotFound);
CHECK(!app.got_subcommand("sub3"));
}
TEST_CASE_METHOD(TApp, "CrazyNameSubcommand", "[subcom]") {