MCPcopy Create free account
hub / github.com/OpenVPN/openvpn3-linux / gen_help_line_generator

Method gen_help_line_generator

src/common/cmdargparser.cpp:557–613  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

555
556
557std::string SingleCommandOption::gen_help_line_generator(const char opt_short,
558 const std::string &opt_long,
559 const std::string &opt_help,
560 const unsigned int width)
561{
562 std::stringstream r;
563
564 // If we don't have a short option, fill out with blanks to
565 // have the long options aligned under each other
566 if (0 == opt_short)
567 {
568 r << " ";
569 }
570 else // ... we have a short option, format the output of it
571 {
572 r << "-" << opt_short << " | ";
573 }
574 r << "--" << opt_long;
575
576 // If this option can process a provided value ...
577 if (!metavar.empty())
578 {
579 // If this value is mandatory, don't include [] around the
580 // the argument value.
581 if (required_argument == getopt_option.has_arg)
582 {
583 r << " " << metavar;
584 }
585 else
586 {
587 // This option is optional, indicate it by embracing the
588 // value description into [].
589 r << "[=" << metavar << "]";
590 }
591 }
592
593 // Ensure the description is aligned with the rest of the lines
594 size_t l = r.str().size();
595
596 if ((width - 3) < l)
597 {
598 // If this first line with the long/short option listing gets too
599 // long, then split it up into several lines.
600 r << std::endl;
601
602 // Set the needed spacing to the description column
603 r << std::setw(width) << " ";
604 }
605 else
606 {
607 // Set the needed spacing to the description column
608 r << std::setw(width - l);
609 }
610 r << " - " << opt_help;
611
612 return r.str();
613}
614

Callers

nothing calls this directly

Calls 3

sizeMethod · 0.80
emptyMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected