Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.

Commit b1f42c2

Browse files
committed
v1.1.3
1 parent 8285092 commit b1f42c2

File tree

4 files changed

+39
-17
lines changed

4 files changed

+39
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Clara v1.1.2
1+
# Clara v1.1.3
22
[![Build Status](https://travis-ci.org/catchorg/Clara.svg?branch=master)](https://travis-ci.org/catchorg/Clara)
33
[![Build status](https://ci.appveyor.com/api/projects/status/github/catchorg/Clara?brach=master&svg=true)](https://ci.appveyor.com/project/catchorg/clara)
44
[![codecov](https://codecov.io/gh/catchorg/Clara/branch/master/graph/badge.svg)](https://codecov.io/gh/catchorg/Clara)

docs/release-notes.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
<a id="top"></a>
22

3+
# 1.1.3
4+
5+
## Improvements
6+
* `Args` now take arguments as `int argc, char const * const * argv`.
7+
* This allows the use of string literals for arguments
8+
9+
310
# 1.1.2
411
* Fix usage of `dynamic_cast` preventing Clara being used with `-fno-rtti`
512

include/clara.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//
66
// See https://github.com/philsquared/Clara for more details
77

8-
// Clara v1.1.2
8+
// Clara v1.1.3
99

1010
#ifndef CLARA_HPP_INCLUDED
1111
#define CLARA_HPP_INCLUDED

single_include/clara.hpp

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//
66
// See https://github.com/philsquared/Clara for more details
77

8-
// Clara v1.1.2
8+
// Clara v1.1.3
99

1010
#ifndef CLARA_HPP_INCLUDED
1111
#define CLARA_HPP_INCLUDED
@@ -18,6 +18,15 @@
1818
#define CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CLARA_CONFIG_CONSOLE_WIDTH
1919
#endif
2020

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+
2130
// ----------- #included from clara_textflow.hpp -----------
2231

2332
// TextFlowCpp
@@ -389,11 +398,9 @@ namespace detail {
389398
std::vector<std::string> m_args;
390399

391400
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) {}
397404

398405
Args( std::initializer_list<std::string> args )
399406
: m_exeName( *args.begin() ),
@@ -580,15 +587,13 @@ namespace detail {
580587

581588
protected:
582589
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();
592597
}
593598

594599
std::string m_errorMessage; // Only populated if resultType is an error
@@ -658,6 +663,16 @@ namespace detail {
658663
return ParserResult::runtimeError( "Expected a boolean value but did not recognise: '" + source + "'" );
659664
return ParserResult::ok( ParseResultType::Matched );
660665
}
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
661676

662677
struct NonCopyable {
663678
NonCopyable() = default;

0 commit comments

Comments
 (0)