1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2025-02-17 11:45:50 +00:00

Move ValidationError to commonlib.

This commit is contained in:
King_DuckZ 2015-12-13 16:33:58 +00:00
parent 986f0c8db3
commit 93a5130cc5
10 changed files with 77 additions and 47 deletions

View file

@ -1,4 +1,4 @@
project(${bare_name}-<command_name_here> CXX C)
project(${bare_name}-<command_name_here> CXX)
add_executable(${PROJECT_NAME}
main.cpp
@ -18,4 +18,3 @@ string(REPLACE "${bare_name}-" "" ACTION_NAME "${PROJECT_NAME}")
target_compile_definitions(${PROJECT_NAME}
PRIVATE ACTION_NAME="${ACTION_NAME}"
)

View file

@ -23,16 +23,6 @@
namespace po = boost::program_options;
namespace din {
ValidationError::ValidationError (const po::validation_error& parOther) :
po::validation_error(parOther)
{
}
const std::string& ValidationError::raw_value() const {
auto it_ret = m_substitutions.find("value");
return it_ret->second;
}
bool parse_commandline (int parArgc, char* parArgv[], po::variables_map& parVarMap) {
po::options_description set_options(ACTION_NAME " options");
//set_options.add_options()
@ -55,7 +45,7 @@ namespace din {
po::store(po::command_line_parser(parArgc, parArgv).options(all)/*.positional(pd)*/.run(), parVarMap);
}
catch (const po::validation_error& err) {
throw ValidationError(err);
throw dinlib::ValidationError(err);
}
po::notify(parVarMap);

View file

@ -18,19 +18,11 @@
#ifndef id1B7A42F6E46547A6AB0F914E2A91399F
#define id1B7A42F6E46547A6AB0F914E2A91399F
#include <boost/program_options/variables_map.hpp>
#include <boost/program_options/errors.hpp>
#include "dindexer-common/validationerror.hpp"
#include "dindexer-common/mediatypes.hpp"
#include <boost/program_options/variables_map.hpp>
namespace din {
class ValidationError : boost::program_options::validation_error {
public:
explicit ValidationError ( const boost::program_options::validation_error& parOther );
~ValidationError ( void ) noexcept = default;
const std::string& raw_value ( void ) const;
};
bool parse_commandline ( int parArgc, char* parArgv[], boost::program_options::variables_map& parVarMap );
} //namespace din

View file

@ -0,0 +1,34 @@
/* Copyright 2015, Michele Santullo
* This file is part of "dindexer".
*
* "dindexer" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* "dindexer" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef id12815ADC9F024C85B9BBC65C5FA50959
#define id12815ADC9F024C85B9BBC65C5FA50959
#include <boost/program_options/errors.hpp>
#include <string>
namespace dinlib {
class ValidationError : boost::program_options::validation_error {
public:
explicit ValidationError ( const boost::program_options::validation_error& parOther );
~ValidationError ( void ) noexcept = default;
const std::string& raw_value ( void ) const;
};
} //namespace dinlib
#endif

View file

@ -4,6 +4,7 @@ add_library(${PROJECT_NAME}
commandline.cpp
mediatypes.cpp
settings.cpp
validationerror.cpp
)
target_include_directories(${PROJECT_NAME}

View file

@ -0,0 +1,33 @@
/* Copyright 2015, Michele Santullo
* This file is part of "dindexer".
*
* "dindexer" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* "dindexer" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
*/
#include "dindexer-common/validationerror.hpp"
#include <boost/program_options/errors.hpp>
namespace po = boost::program_options;
namespace dinlib {
ValidationError::ValidationError (const po::validation_error& parOther) :
po::validation_error(parOther)
{
}
const std::string& ValidationError::raw_value() const {
auto it_ret = m_substitutions.find("value");
return it_ret->second;
}
} //namespace dinlib

View file

@ -1,4 +1,4 @@
project(${bare_name}-delete CXX C)
project(${bare_name}-delete CXX)
add_executable(${PROJECT_NAME}
main.cpp
@ -19,4 +19,3 @@ string(REPLACE "${bare_name}-" "" ACTION_NAME "${PROJECT_NAME}")
target_compile_definitions(${PROJECT_NAME}
PRIVATE ACTION_NAME="${ACTION_NAME}"
)

View file

@ -25,16 +25,6 @@
namespace po = boost::program_options;
namespace din {
ValidationError::ValidationError (const po::validation_error& parOther) :
po::validation_error(parOther)
{
}
const std::string& ValidationError::raw_value() const {
auto it_ret = m_substitutions.find("value");
return it_ret->second;
}
bool parse_commandline (int parArgc, char* parArgv[], po::variables_map& parVarMap) {
po::options_description set_options(ACTION_NAME " options");
set_options.add_options()
@ -56,7 +46,7 @@ namespace din {
po::store(po::command_line_parser(parArgc, parArgv).options(all).positional(pd).run(), parVarMap);
}
catch (const po::validation_error& err) {
throw ValidationError(err);
throw dinlib::ValidationError(err);
}
po::notify(parVarMap);

View file

@ -18,19 +18,11 @@
#ifndef idB6191389C4AD4EE5862CCF1591BE6CE5
#define idB6191389C4AD4EE5862CCF1591BE6CE5
#include <boost/program_options/variables_map.hpp>
#include <boost/program_options/errors.hpp>
#include "dindexer-common/validationerror.hpp"
#include "dindexer-common/mediatypes.hpp"
#include <boost/program_options/variables_map.hpp>
namespace din {
class ValidationError : boost::program_options::validation_error {
public:
explicit ValidationError ( const boost::program_options::validation_error& parOther );
~ValidationError ( void ) noexcept = default;
const std::string& raw_value ( void ) const;
};
bool parse_commandline ( int parArgc, char* parArgv[], boost::program_options::variables_map& parVarMap );
} //namespace din

View file

@ -56,7 +56,7 @@ int main (int parArgc, char* parArgv[]) {
std::cerr << err.what() << "\nUse --help for help" << std::endl;
return 2;
}
catch (const din::ValidationError& err) {
catch (const dinlib::ValidationError& err) {
std::cerr << "Unrecognized id \"" << err.raw_value() << "\", see --help for usage details\n";
return 2;
}