From b3ab0229df3bc868cc91aae7f09daeef4b3dea53 Mon Sep 17 00:00:00 2001 From: Tessa Todorowski Date: Wed, 27 Mar 2024 13:07:46 +0100 Subject: [PATCH 1/3] add test case --- test/test_help.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/test_help.cpp b/test/test_help.cpp index 382a92b9..78f96ea6 100644 --- a/test/test_help.cpp +++ b/test/test_help.cpp @@ -244,3 +244,12 @@ TEST_CASE("multiline usage, break on mutex") { " [--will-go-on-new-line]\n" " [--on-a-dedicated-line]"); } + +TEST_CASE("Usage output with subparser") { + argparse::ArgumentParser program("program"); + argparse::ArgumentParser sub("sub"); + program.add_subparser(sub); + // std::cout << "DEBUG:" << program.usage() << std::endl; + REQUIRE(program.usage() == "Usage: program [--help] [--version] {sub}"); + REQUIRE(sub.usage() == "Usage: program sub [--help] [--version]"); +} From 7b7e78cb9ca3bb8c030e0ee8f5ec83b75f98f58e Mon Sep 17 00:00:00 2001 From: Tessa Todorowski Date: Wed, 27 Mar 2024 13:08:35 +0100 Subject: [PATCH 2/3] Usage page: replace m_program_name with m_parser_path --- include/argparse/argparse.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/argparse/argparse.hpp b/include/argparse/argparse.hpp index ba546e33..39af3115 100644 --- a/include/argparse/argparse.hpp +++ b/include/argparse/argparse.hpp @@ -2010,7 +2010,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::max(); const size_t indent_size = curline.size(); From 14ba7c8d9ab97f6b80b9e8c5241af8630a5f498c Mon Sep 17 00:00:00 2001 From: Tessa Todorowski Date: Wed, 27 Mar 2024 14:25:09 +0100 Subject: [PATCH 3/3] Readme: update subparser usage examples --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2196ce9b..353d81b2 100644 --- a/README.md +++ b/README.md @@ -895,7 +895,7 @@ Subcommands: submodule Initialize, update or inspect submodules foo@bar:/home/dev/$ ./git add --help -Usage: add [-h] files +Usage: git add [-h] files Add file contents to the index @@ -907,7 +907,7 @@ Optional arguments: -v, --version prints version information and exits foo@bar:/home/dev/$ ./git commit --help -Usage: commit [-h] [--all] [--message VAR] +Usage: git commit [-h] [--all] [--message VAR] Record changes to the repository @@ -918,7 +918,7 @@ Optional arguments: -m, --message Use the given as the commit message. foo@bar:/home/dev/$ ./git submodule --help -Usage: submodule [-h] {update} +Usage: git submodule [-h] {update} Initialize, update or inspect submodules @@ -957,7 +957,7 @@ Optional arguments: -v, --version prints version information and exits foo@bar:/home/dev/$ ./main hidden -h -Usage: hidden [--help] [--version] files +Usage: test hidden [--help] [--version] files Positional arguments: files [nargs: 0 or more]