From 5b3bb436392856a4f75ff826080972c3304bd8cb Mon Sep 17 00:00:00 2001 From: AmirHossein Sojoodi Date: Thu, 30 Nov 2023 13:54:41 -0500 Subject: [PATCH 1/2] Print long names in help option Related to #240, #363, and #349 --- include/cxxopts.hpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/include/cxxopts.hpp b/include/cxxopts.hpp index a5c67f1..7a15d8e 100644 --- a/include/cxxopts.hpp +++ b/include/cxxopts.hpp @@ -2150,9 +2150,21 @@ format_option result += " "; } - if (!l.empty()) + auto is_first_name = true; + for (const auto& name : o.l) { - result += " --" + toLocalString(l); + if (!name.empty()) + { + if (is_first_name) + { + result += " --" + toLocalString(name); + is_first_name = false; + } + else + { + result += ", --" + toLocalString(name); + } + } } auto arg = !o.arg_help.empty() ? toLocalString(o.arg_help) : "arg"; From df305deeaa10b2fa4384550376b5774de01f7fea Mon Sep 17 00:00:00 2001 From: amirsojoodi Date: Mon, 29 Dec 2025 00:36:58 -0500 Subject: [PATCH 2/2] Add unit test to print aliases --- test/options.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/options.cpp b/test/options.cpp index 6df4972..ff944ac 100644 --- a/test/options.cpp +++ b/test/options.cpp @@ -1191,3 +1191,15 @@ TEST_CASE("No Options help", "[options]") CHECK_NOTHROW(options.parse(argc, argv)); CHECK(options.help().find("test ...") != std::string::npos); } + +TEST_CASE("Help shows all aliases", "[help]") +{ + cxxopts::Options options("Print all aliases", " - ensure help lists every long name"); + + options.add_options() + ("v,verify,ver", "Verification option", cxxopts::value()); + + const auto help = options.help(); + + CHECK(help.find("-v, --ver, --verify arg") != std::string::npos); +}