diff --git a/src/cxxopts.hpp b/src/cxxopts.hpp index ed93ffd..2e24feb 100644 --- a/src/cxxopts.hpp +++ b/src/cxxopts.hpp @@ -594,6 +594,7 @@ namespace cxxopts bool has_arg; bool has_default; std::string default_value; + std::string arg_help; }; struct HelpGroupDetails @@ -629,7 +630,8 @@ namespace cxxopts const std::string& s, const std::string& l, std::string desc, - std::shared_ptr value + std::shared_ptr value, + std::string arg_help ); int @@ -734,7 +736,8 @@ namespace cxxopts const std::string& opts, const std::string& desc, std::shared_ptr value - = ::cxxopts::value() + = ::cxxopts::value(), + std::string arg_help = "" ); private: @@ -786,7 +789,14 @@ namespace cxxopts if (o.has_arg) { - result += " arg"; + if (o.arg_help.size() != 0) + { + result += " " + toLocalString(o.arg_help); + } + else + { + result += " arg"; + } if (o.has_default) { @@ -865,7 +875,8 @@ OptionAdder::operator() ( const std::string& opts, const std::string& desc, - std::shared_ptr value + std::shared_ptr value, + std::string arg_help ) { std::match_results result; @@ -879,7 +890,8 @@ OptionAdder::operator() const auto& s = result[2]; const auto& l = result[3]; - m_options.add_option(m_group, s.str(), l.str(), desc, value); + m_options.add_option(m_group, s.str(), l.str(), desc, value, + std::move(arg_help)); return *this; } @@ -1100,7 +1112,8 @@ Options::add_option const std::string& s, const std::string& l, std::string desc, - std::shared_ptr value + std::shared_ptr value, + std::string arg_help ) { auto stringDesc = toLocalString(std::move(desc)); @@ -1118,9 +1131,10 @@ Options::add_option //add the help details auto& options = m_help[group]; - + options.options.emplace_back(HelpOptionDetails{s, l, stringDesc, - value->has_arg(), value->has_default(), value->get_default_value()}); + value->has_arg(), value->has_default(), value->get_default_value(), + std::move(arg_help)}); } void diff --git a/src/example.cpp b/src/example.cpp index a453544..6566569 100644 --- a/src/example.cpp +++ b/src/example.cpp @@ -37,7 +37,7 @@ int main(int argc, char* argv[]) options.add_options() ("a,apple", "an apple", cxxopts::value(apple)) ("b,bob", "Bob") - ("f,file", "File", cxxopts::value>()) + ("f,file", "File", cxxopts::value>(), "FILE") ("o,output", "Output file", cxxopts::value() ->default_value("a.out")->implicit_value("b.def")) ("positional", @@ -46,7 +46,7 @@ int main(int argc, char* argv[]) ("long-description", "thisisareallylongwordthattakesupthewholelineandcannotbebrokenataspace") ("help", "Print help") - ("int", "An integer", cxxopts::value()) + ("int", "An integer", cxxopts::value(), "N") ("option_that_is_too_long_for_the_help", "A very long option") #ifdef CXXOPTS_USE_UNICODE ("unicode", u8"A help option with non-ascii: à. Here the size of the"