Commit 2bf1060d0bd4488b778a19041062ebdba3f41a0c
1 parent
fd3d4bb2
start option groups
Showing
2 changed files
with
10 additions
and
7 deletions
src/cxxopts.cpp
| ... | ... | @@ -129,9 +129,9 @@ namespace cxxopts |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | OptionAdder |
| 132 | -Options::add_options() | |
| 132 | +Options::add_options(std::string group) | |
| 133 | 133 | { |
| 134 | - return OptionAdder(*this); | |
| 134 | + return OptionAdder(*this, std::move(group)); | |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | OptionAdder& |
| ... | ... | @@ -153,7 +153,7 @@ OptionAdder::operator() |
| 153 | 153 | const auto& s = result[2]; |
| 154 | 154 | const auto& l = result[3]; |
| 155 | 155 | |
| 156 | - m_options.add_option(s.str(), l.str(), desc, value); | |
| 156 | + m_options.add_option(m_group, s.str(), l.str(), desc, value); | |
| 157 | 157 | |
| 158 | 158 | return *this; |
| 159 | 159 | } |
| ... | ... | @@ -342,6 +342,7 @@ Options::parse(int& argc, char**& argv) |
| 342 | 342 | void |
| 343 | 343 | Options::add_option |
| 344 | 344 | ( |
| 345 | + const std::string& group, | |
| 345 | 346 | const std::string& s, |
| 346 | 347 | const std::string& l, |
| 347 | 348 | const std::string& desc, |
| ... | ... | @@ -361,7 +362,7 @@ Options::add_option |
| 361 | 362 | } |
| 362 | 363 | |
| 363 | 364 | //add the help details |
| 364 | - auto& options = m_help[""]; | |
| 365 | + auto& options = m_help[group]; | |
| 365 | 366 | options.push_back(HelpDetails{s, l, desc, value->has_arg()}); |
| 366 | 367 | } |
| 367 | 368 | ... | ... |
src/cxxopts.hpp
| ... | ... | @@ -333,11 +333,12 @@ namespace cxxopts |
| 333 | 333 | parse(int& argc, char**& argv); |
| 334 | 334 | |
| 335 | 335 | OptionAdder |
| 336 | - add_options(); | |
| 336 | + add_options(std::string group = ""); | |
| 337 | 337 | |
| 338 | 338 | void |
| 339 | 339 | add_option |
| 340 | 340 | ( |
| 341 | + const std::string& group, | |
| 341 | 342 | const std::string& s, |
| 342 | 343 | const std::string& l, |
| 343 | 344 | const std::string& desc, |
| ... | ... | @@ -420,8 +421,8 @@ namespace cxxopts |
| 420 | 421 | { |
| 421 | 422 | public: |
| 422 | 423 | |
| 423 | - OptionAdder(Options& options) | |
| 424 | - : m_options(options) | |
| 424 | + OptionAdder(Options& options, std::string group) | |
| 425 | + : m_options(options), m_group(std::move(group)) | |
| 425 | 426 | { |
| 426 | 427 | } |
| 427 | 428 | |
| ... | ... | @@ -436,6 +437,7 @@ namespace cxxopts |
| 436 | 437 | |
| 437 | 438 | private: |
| 438 | 439 | Options& m_options; |
| 440 | + std::string m_group; | |
| 439 | 441 | }; |
| 440 | 442 | |
| 441 | 443 | } | ... | ... |