Commit 3c3d2003ca999302f7a14dcbba2af9485510334d
1 parent
1be5f10d
add help for positional parameters
Showing
2 changed files
with
12 additions
and
1 deletions
include/cxxopts.hpp
| @@ -681,11 +681,20 @@ namespace cxxopts | @@ -681,11 +681,20 @@ namespace cxxopts | ||
| 681 | Options(std::string program, std::string help_string = "") | 681 | Options(std::string program, std::string help_string = "") |
| 682 | : m_program(std::move(program)) | 682 | : m_program(std::move(program)) |
| 683 | , m_help_string(toLocalString(std::move(help_string))) | 683 | , m_help_string(toLocalString(std::move(help_string))) |
| 684 | + , m_positional_help("positional parameters") | ||
| 684 | , m_next_positional(m_positional.end()) | 685 | , m_next_positional(m_positional.end()) |
| 685 | { | 686 | { |
| 686 | } | 687 | } |
| 687 | 688 | ||
| 688 | inline | 689 | inline |
| 690 | + Options& | ||
| 691 | + positional_help(const std::string& help_text) | ||
| 692 | + { | ||
| 693 | + m_positional_help = std::move(help_text); | ||
| 694 | + return *this; | ||
| 695 | + } | ||
| 696 | + | ||
| 697 | + inline | ||
| 689 | void | 698 | void |
| 690 | parse(int& argc, char**& argv); | 699 | parse(int& argc, char**& argv); |
| 691 | 700 | ||
| @@ -795,6 +804,7 @@ namespace cxxopts | @@ -795,6 +804,7 @@ namespace cxxopts | ||
| 795 | 804 | ||
| 796 | std::string m_program; | 805 | std::string m_program; |
| 797 | String m_help_string; | 806 | String m_help_string; |
| 807 | + std::string m_positional_help; | ||
| 798 | 808 | ||
| 799 | std::map<std::string, std::shared_ptr<OptionDetails>> m_options; | 809 | std::map<std::string, std::shared_ptr<OptionDetails>> m_options; |
| 800 | std::vector<std::string> m_positional; | 810 | std::vector<std::string> m_positional; |
| @@ -1369,7 +1379,7 @@ Options::help(const std::vector<std::string>& groups) const | @@ -1369,7 +1379,7 @@ Options::help(const std::vector<std::string>& groups) const | ||
| 1369 | toLocalString(m_program) + " [OPTION...]"; | 1379 | toLocalString(m_program) + " [OPTION...]"; |
| 1370 | 1380 | ||
| 1371 | if (m_positional.size() > 0) { | 1381 | if (m_positional.size() > 0) { |
| 1372 | - result += " positional parameters"; | 1382 | + result += " " + toLocalString(m_positional_help); |
| 1373 | } | 1383 | } |
| 1374 | 1384 | ||
| 1375 | result += "\n\n"; | 1385 | result += "\n\n"; |
src/example.cpp
| @@ -31,6 +31,7 @@ int main(int argc, char* argv[]) | @@ -31,6 +31,7 @@ int main(int argc, char* argv[]) | ||
| 31 | try | 31 | try |
| 32 | { | 32 | { |
| 33 | cxxopts::Options options(argv[0], " - example command line options"); | 33 | cxxopts::Options options(argv[0], " - example command line options"); |
| 34 | + options.positional_help("[optional args]"); | ||
| 34 | 35 | ||
| 35 | bool apple = false; | 36 | bool apple = false; |
| 36 | 37 |