Commit c8b22d113db95260a583fa7884a7da59c4a7c3a9

Authored by Jarryd Beck
1 parent 2bf1060d

print usage

src/cxxopts.cpp
... ... @@ -396,7 +396,8 @@ Options::help() const
396 396  
397 397 size_t longest = 0;
398 398  
399   - std::string result;
  399 + std::string result = "Usage:\n " + m_program + " [OPTION...] "
  400 + + m_help_string + "\n\n";
400 401  
401 402 for (const auto& o : group->second)
402 403 {
... ...
src/cxxopts.hpp
... ... @@ -329,6 +329,12 @@ namespace cxxopts
329 329 {
330 330 public:
331 331  
  332 + Options(std::string program, std::string help_string = "")
  333 + : m_program(std::move(program))
  334 + , m_help_string(std::move(help_string))
  335 + {
  336 + }
  337 +
332 338 void
333 339 parse(int& argc, char**& argv);
334 340  
... ... @@ -410,6 +416,9 @@ namespace cxxopts
410 416 const std::string& name
411 417 );
412 418  
  419 + std::string m_program;
  420 + std::string m_help_string;
  421 +
413 422 std::map<std::string, std::shared_ptr<OptionDetails>> m_options;
414 423 std::string m_positional;
415 424  
... ...
src/example.cpp
... ... @@ -31,7 +31,7 @@ int main(int argc, char* argv[])
31 31 try
32 32 {
33 33  
34   - cxxopts::Options options;
  34 + cxxopts::Options options(argv[0]);
35 35  
36 36 options.add_options()
37 37 ("a,apple", "an apple")
... ...