| 7642 | } |
| 7643 | |
| 7644 | void writeToStream( std::ostream &os ) const { |
| 7645 | if (!m_exeName.name().empty()) { |
| 7646 | os << "usage:\n" << " " << m_exeName.name() << " "; |
| 7647 | bool required = true, first = true; |
| 7648 | for( auto const &arg : m_args ) { |
| 7649 | if (first) |
| 7650 | first = false; |
| 7651 | else |
| 7652 | os << " "; |
| 7653 | if( arg.isOptional() && required ) { |
| 7654 | os << "["; |
| 7655 | required = false; |
| 7656 | } |
| 7657 | os << "<" << arg.hint() << ">"; |
| 7658 | if( arg.cardinality() == 0 ) |
| 7659 | os << " ... "; |
| 7660 | } |
| 7661 | if( !required ) |
| 7662 | os << "]"; |
| 7663 | if( !m_options.empty() ) |
| 7664 | os << " options"; |
| 7665 | os << "\n\nwhere options are:" << std::endl; |
| 7666 | } |
| 7667 | |
| 7668 | auto rows = getHelpColumns(); |
| 7669 | size_t consoleWidth = CATCH_CLARA_CONFIG_CONSOLE_WIDTH; |
| 7670 | size_t optWidth = 0; |
| 7671 | for( auto const &cols : rows ) |
| 7672 | optWidth = (std::max)(optWidth, cols.left.size() + 2); |
| 7673 | |
| 7674 | optWidth = (std::min)(optWidth, consoleWidth/2); |
| 7675 | |
| 7676 | for( auto const &cols : rows ) { |
| 7677 | auto row = |
| 7678 | TextFlow::Column( cols.left ).width( optWidth ).indent( 2 ) + |
| 7679 | TextFlow::Spacer(4) + |
| 7680 | TextFlow::Column( cols.right ).width( consoleWidth - 7 - optWidth ); |
| 7681 | os << row << std::endl; |
| 7682 | } |
| 7683 | } |
| 7684 | |
| 7685 | friend auto operator<<( std::ostream &os, Parser const &parser ) -> std::ostream& { |
| 7686 | parser.writeToStream( os ); |
no test coverage detected