Commit f291f3a8 authored by wiebel's avatar wiebel
Browse files

[ADD] added handling of command-line option errors

parent 54799e56
......@@ -25,14 +25,35 @@
#include "BOptionHandler.h"
BOptionHandler::BOptionHandler( int argc, char* argv[] )
: m_argc( argc ),
m_argv( argv ),
m_desc( "Allowed options" ),
BOptionHandler::BOptionHandler( int argc, char* argv[] )
: m_argc( argc ),
m_argv( argv ),
m_errorOccured( false ),
m_desc( "Allowed options" ),
m_map()
{
createOptions();
parseOptions();
try
{
parseOptions();
}
catch( po::multiple_occurrences error )
{
m_errorOccured = true;
std::cout << "Command-line option error: each option is allowed only once" << std::endl;
}
catch( po::unknown_option error )
{
m_errorOccured = true;
std::cout << "Command-line option error: " << error.what() << std::endl;
std::cout << m_desc << std::endl;
}
catch( po::error error )
{
m_errorOccured = true;
std::cout << "Unknown command-line option error: " << error.what() << std::endl;
std::cout << m_desc << std::endl;
}
}
void BOptionHandler::createOptions()
......@@ -49,7 +70,13 @@ void BOptionHandler::parseOptions()
int BOptionHandler::takeActions()
{
if( m_map.count( "help" ) ) {
if( m_errorOccured )
{
return 1;
}
if( m_map.count( "help" ) )
{
std::cout << m_desc << std::endl;
return 0;
}
......
......@@ -54,6 +54,7 @@ protected:
private:
int m_argc;
char** m_argv;
bool m_errorOccured;
/**
* Stores the option definition such as type, name and description.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment