From 9b4c63a2d838fdbe2e1e1f3c2c9d6b432ddd19f9 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Mon, 20 Jan 2025 15:55:01 +0100 Subject: [PATCH] usage(): do not emit blank line when a single argument exceeds set_usage_max_line_width() --- include/argparse/argparse.hpp | 3 ++- test/test_help.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/argparse/argparse.hpp b/include/argparse/argparse.hpp index c8c99b6..57a34f6 100644 --- a/include/argparse/argparse.hpp +++ b/include/argparse/argparse.hpp @@ -2128,7 +2128,8 @@ public: } } cur_mutex = arg_mutex; - if (curline.size() + 1 + arg_inline_usage.size() > + if (curline.size() != indent_size && + curline.size() + 1 + arg_inline_usage.size() > this->m_usage_max_line_width) { stream << curline << std::endl; curline = std::string(indent_size, ' '); diff --git a/test/test_help.cpp b/test/test_help.cpp index 382a92b..a5572ca 100644 --- a/test/test_help.cpp +++ b/test/test_help.cpp @@ -244,3 +244,13 @@ TEST_CASE("multiline usage, break on mutex") { " [--will-go-on-new-line]\n" " [--on-a-dedicated-line]"); } + +TEST_CASE("multiline usage, single arg that is larger than the max width") { + argparse::ArgumentParser program("program"); + program.set_usage_max_line_width(80); + program.add_argument("--lots-of-choices").metavar(""); + // std::cout << "DEBUG:" << program.usage() << std::endl; + REQUIRE(program.usage() == + "Usage: program [--help] [--version]\n" + " [--lots-of-choices ]"); +}