| 476 | |
| 477 | |
| 478 | void |
| 479 | ArgParse::usage () const |
| 480 | { |
| 481 | const size_t longline = 40; |
| 482 | std::cout << m_intro << '\n'; |
| 483 | size_t maxlen = 0; |
| 484 | |
| 485 | for (unsigned int i=0; i<m_option.size(); ++i) { |
| 486 | ArgOption *opt = m_option[i]; |
| 487 | size_t fmtlen = opt->fmt().length(); |
| 488 | // Option lists > 40 chars will be split into multiple lines |
| 489 | if (fmtlen < longline) |
| 490 | maxlen = std::max (maxlen, fmtlen); |
| 491 | } |
| 492 | |
| 493 | for (unsigned int i=0; i<m_option.size(); ++i) { |
| 494 | ArgOption *opt = m_option[i]; |
| 495 | if (opt->description().length()) { |
| 496 | size_t fmtlen = opt->fmt().length(); |
| 497 | if (opt->fmt() == "<SEPARATOR>") |
| 498 | std::cout << opt->description() << '\n'; |
| 499 | else if (fmtlen < longline) |
| 500 | std::cout << " " << opt->fmt() |
| 501 | << std::string (maxlen + 2 - fmtlen, ' ') |
| 502 | << opt->description() << '\n'; |
| 503 | else |
| 504 | std::cout << " " << opt->fmt() << "\n " |
| 505 | << std::string (maxlen + 2, ' ') |
| 506 | << opt->description() << '\n'; |
| 507 | } |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | |
| 512 | |