| 7480 | } |
| 7481 | |
| 7482 | class Opt : public ParserRefImpl<Opt> { |
| 7483 | protected: |
| 7484 | std::vector<std::string> m_optNames; |
| 7485 | |
| 7486 | public: |
| 7487 | template<typename LambdaT> |
| 7488 | explicit Opt( LambdaT const &ref ) : ParserRefImpl( std::make_shared<BoundFlagLambda<LambdaT>>( ref ) ) {} |
| 7489 | |
| 7490 | explicit Opt( bool &ref ) : ParserRefImpl( std::make_shared<BoundFlagRef>( ref ) ) {} |
| 7491 | |
| 7492 | template<typename LambdaT> |
| 7493 | Opt( LambdaT const &ref, std::string const &hint ) : ParserRefImpl( ref, hint ) {} |
| 7494 | |
| 7495 | template<typename T> |
| 7496 | Opt( T &ref, std::string const &hint ) : ParserRefImpl( ref, hint ) {} |
| 7497 | |
| 7498 | auto operator[]( std::string const &optName ) -> Opt & { |
| 7499 | m_optNames.push_back( optName ); |
| 7500 | return *this; |
| 7501 | } |
| 7502 | |
| 7503 | auto getHelpColumns() const -> std::vector<HelpColumns> { |
| 7504 | std::ostringstream oss; |
| 7505 | bool first = true; |
| 7506 | for( auto const &opt : m_optNames ) { |
| 7507 | if (first) |
| 7508 | first = false; |
| 7509 | else |
| 7510 | oss << ", "; |
| 7511 | oss << opt; |
| 7512 | } |
| 7513 | if( !m_hint.empty() ) |
| 7514 | oss << " <" << m_hint << ">"; |
| 7515 | return { { oss.str(), m_description } }; |
| 7516 | } |
| 7517 | |
| 7518 | auto isMatch( std::string const &optToken ) const -> bool { |
| 7519 | auto normalisedToken = normaliseOpt( optToken ); |
| 7520 | for( auto const &name : m_optNames ) { |
| 7521 | if( normaliseOpt( name ) == normalisedToken ) |
| 7522 | return true; |
| 7523 | } |
| 7524 | return false; |
| 7525 | } |
| 7526 | |
| 7527 | using ParserBase::parse; |
| 7528 | |
| 7529 | auto parse( std::string const&, TokenStream const &tokens ) const -> InternalParseResult override { |
| 7530 | auto validationResult = validate(); |
| 7531 | if( !validationResult ) |
| 7532 | return InternalParseResult( validationResult ); |
| 7533 | |
| 7534 | auto remainingTokens = tokens; |
| 7535 | if( remainingTokens && remainingTokens->type == TokenType::Option ) { |
| 7536 | auto const &token = *remainingTokens; |
| 7537 | if( isMatch(token.token ) ) { |
| 7538 | if( m_ref->isFlag() ) { |
| 7539 | auto flagRef = static_cast<detail::BoundFlagRefBase*>( m_ref.get() ); |
no outgoing calls
no test coverage detected