Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subparser: use full parser path instead of just parser name in usage() message #382

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tidy-analysis-stage-01.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
echo ${{ github.event.pull_request.head.repo.full_name }} > clang-tidy-result/pr-head-repo.txt
echo ${{ github.event.pull_request.head.ref }} > clang-tidy-result/pr-head-ref.txt

- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
with:
name: clang-tidy-result
path: clang-tidy-result/
2 changes: 1 addition & 1 deletion include/argparse/argparse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2067,7 +2067,7 @@ class ArgumentParser {
std::stringstream stream;

std::string curline("Usage: ");
curline += this->m_program_name;
curline += this->m_parser_path;
const bool multiline_usage =
this->m_usage_max_line_width < (std::numeric_limits<std::size_t>::max)();
const size_t indent_size = curline.size();
Expand Down
26 changes: 26 additions & 0 deletions test/test_subparsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,29 @@ TEST_CASE("Check set_suppress" * test_suite("subparsers")) {
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