|
5 | 5 | // |
6 | 6 | // See https://github.com/philsquared/Clara for more details |
7 | 7 |
|
8 | | -// Clara v1.1.2 |
| 8 | +// Clara v1.1.3 |
9 | 9 |
|
10 | 10 | #ifndef CLARA_HPP_INCLUDED |
11 | 11 | #define CLARA_HPP_INCLUDED |
|
18 | 18 | #define CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CLARA_CONFIG_CONSOLE_WIDTH |
19 | 19 | #endif |
20 | 20 |
|
| 21 | +#ifndef CLARA_CONFIG_OPTIONAL_TYPE |
| 22 | +#ifdef __has_include |
| 23 | +#if __has_include(<optional>) && __cplusplus >= 201703L |
| 24 | +#define CLARA_CONFIG_OPTIONAL_TYPE std::optional |
| 25 | +#endif |
| 26 | +#endif |
| 27 | +#endif |
| 28 | + |
| 29 | + |
21 | 30 | // ----------- #included from clara_textflow.hpp ----------- |
22 | 31 |
|
23 | 32 | // TextFlowCpp |
@@ -389,11 +398,9 @@ namespace detail { |
389 | 398 | std::vector<std::string> m_args; |
390 | 399 |
|
391 | 400 | public: |
392 | | - Args( int argc, char *argv[] ) { |
393 | | - m_exeName = argv[0]; |
394 | | - for( int i = 1; i < argc; ++i ) |
395 | | - m_args.push_back( argv[i] ); |
396 | | - } |
| 401 | + Args( int argc, char const* const* argv ) |
| 402 | + : m_exeName(argv[0]), |
| 403 | + m_args(argv + 1, argv + argc) {} |
397 | 404 |
|
398 | 405 | Args( std::initializer_list<std::string> args ) |
399 | 406 | : m_exeName( *args.begin() ), |
@@ -580,15 +587,13 @@ namespace detail { |
580 | 587 |
|
581 | 588 | protected: |
582 | 589 | void enforceOk() const override { |
583 | | - // !TBD: If no exceptions, std::terminate here or something |
584 | | - switch( m_type ) { |
585 | | - case ResultBase::LogicError: |
586 | | - throw std::logic_error( m_errorMessage ); |
587 | | - case ResultBase::RuntimeError: |
588 | | - throw std::runtime_error( m_errorMessage ); |
589 | | - case ResultBase::Ok: |
590 | | - break; |
591 | | - } |
| 590 | + |
| 591 | + // Errors shouldn't reach this point, but if they do |
| 592 | + // the actual error message will be in m_errorMessage |
| 593 | + assert( m_type != ResultBase::LogicError ); |
| 594 | + assert( m_type != ResultBase::RuntimeError ); |
| 595 | + if( m_type != ResultBase::Ok ) |
| 596 | + std::abort(); |
592 | 597 | } |
593 | 598 |
|
594 | 599 | std::string m_errorMessage; // Only populated if resultType is an error |
@@ -658,6 +663,16 @@ namespace detail { |
658 | 663 | return ParserResult::runtimeError( "Expected a boolean value but did not recognise: '" + source + "'" ); |
659 | 664 | return ParserResult::ok( ParseResultType::Matched ); |
660 | 665 | } |
| 666 | +#ifdef CLARA_CONFIG_OPTIONAL_TYPE |
| 667 | + template<typename T> |
| 668 | + inline auto convertInto( std::string const &source, std::optional<T>& target ) -> ParserResult { |
| 669 | + T temp; |
| 670 | + auto result = convertInto( source, temp ); |
| 671 | + if( result ) |
| 672 | + target = temp; |
| 673 | + return result; |
| 674 | + } |
| 675 | +#endif // CLARA_CONFIG_OPTIONAL_TYPE |
661 | 676 |
|
662 | 677 | struct NonCopyable { |
663 | 678 | NonCopyable() = default; |
|
0 commit comments