diff options
| author | Martin Hořeňovský | 2022-04-04 15:38:25 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2022-04-05 13:42:21 +0200 |
| commit | 8ac86495de5bf249fd50775335f62eedb77815d6 (patch) | |
| tree | 1f1453b5e5633ec20e80c6db7847b3a08faf920e /src/catch2/internal | |
| parent | d750da13a8ca2ffcd00ba49d52ee8044287aa31b (diff) | |
| download | catch3-8ac86495de5bf249fd50775335f62eedb77815d6.tar.gz | |
Cleanup ColourMode parsing in CLI
Diffstat (limited to 'src/catch2/internal')
| -rw-r--r-- | src/catch2/internal/catch_commandline.cpp | 41 |
1 files changed, 11 insertions, 30 deletions
diff --git a/src/catch2/internal/catch_commandline.cpp b/src/catch2/internal/catch_commandline.cpp index 6363e47a..5095f1db 100644 --- a/src/catch2/internal/catch_commandline.cpp +++ b/src/catch2/internal/catch_commandline.cpp @@ -14,6 +14,7 @@ #include <catch2/interfaces/catch_interfaces_reporter_registry.hpp> #include <catch2/interfaces/catch_interfaces_reporter.hpp> #include <catch2/internal/catch_console_colour.hpp> +#include <catch2/internal/catch_reporter_spec_parser.hpp> #include <algorithm> #include <fstream> @@ -98,40 +99,20 @@ namespace Catch { }; auto const setColourMode = [&]( std::string const& colourMode ) { - auto mode = toLower( colourMode ); - - if ( mode == "default" ) { - if ( !isColourImplAvailable( ColourMode::PlatformDefault ) ) { - return ParserResult::runtimeError( - "colour mode 'default' is not supported in this " - "binary" ); - } - config.colourMode = ColourMode::PlatformDefault; - } else if ( mode == "ansi" ) { - if ( !isColourImplAvailable( ColourMode::ANSI ) ) { - return ParserResult::runtimeError( - "colour mode 'ansi' is not supported in this binary" ); - } - config.colourMode = ColourMode::ANSI; - } else if ( mode == "win32" ) { - if ( !isColourImplAvailable( ColourMode::Win32 ) ) { - return ParserResult::runtimeError( - "colour mode 'win32' is not supported in this " - "binary" ); - } - config.colourMode = ColourMode::Win32; - } else if ( mode == "none" ) { - if ( !isColourImplAvailable( ColourMode::None ) ) { - return ParserResult::runtimeError( - "colour mode 'none' is not supported in this binary" ); - } - config.colourMode = ColourMode::None; - } else { + Optional<ColourMode> maybeMode = Catch::Detail::stringToColourMode(toLower( colourMode )); + if ( !maybeMode ) { return ParserResult::runtimeError( "colour mode must be one of: default, ansi, win32, " "or none. '" + - colourMode + "' not recognised" ); + colourMode + "' is not recognised" ); + } + auto mode = *maybeMode; + if ( !isColourImplAvailable( mode ) ) { + return ParserResult::runtimeError( + "colour mode '" + colourMode + + "' is not supported in this binary" ); } + config.colourMode = mode; return ParserResult::ok( ParseResultType::Matched ); }; auto const setWaitForKeypress = [&]( std::string const& keypress ) { |