2015-09-06 20:19:09 +02:00
|
|
|
#include "./failure.h"
|
2015-04-22 18:36:40 +02:00
|
|
|
|
2017-09-29 17:14:57 +02:00
|
|
|
#include "../io/ansiescapecodes.h"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
2015-04-22 18:36:40 +02:00
|
|
|
namespace ApplicationUtilities {
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \class ApplicationUtilities::Failure
|
2016-06-10 22:59:22 +02:00
|
|
|
* \brief The Failure class is thrown by an ArgumentParser when a parsing error occurs.
|
2015-04-22 18:36:40 +02:00
|
|
|
*
|
|
|
|
* \sa ApplicationUtilities::ArgumentParser
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Constructs a new Failure.
|
|
|
|
*/
|
2017-05-01 03:13:11 +02:00
|
|
|
Failure::Failure()
|
|
|
|
: m_what("unspecified parsing exception")
|
|
|
|
{
|
|
|
|
}
|
2015-04-22 18:36:40 +02:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Constructs a new Failure. \a what is a std::string
|
|
|
|
* describing the cause of the Failure.
|
|
|
|
*/
|
2017-05-01 03:13:11 +02:00
|
|
|
Failure::Failure(const std::string &what)
|
|
|
|
: m_what(what)
|
|
|
|
{
|
|
|
|
}
|
2015-04-22 18:36:40 +02:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Destroys the Failure.
|
|
|
|
*/
|
|
|
|
Failure::~Failure() USE_NOTHROW
|
2017-05-01 03:13:11 +02:00
|
|
|
{
|
|
|
|
}
|
2015-04-22 18:36:40 +02:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Returns a C-style character string describing the cause
|
|
|
|
* of the Failure.
|
|
|
|
*/
|
|
|
|
const char *Failure::what() const USE_NOTHROW
|
|
|
|
{
|
|
|
|
return m_what.c_str();
|
|
|
|
}
|
2017-09-29 17:14:57 +02:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Prints an error message "Unable to parse arguments: ..." for the specified \a failure.
|
|
|
|
*/
|
|
|
|
std::ostream &operator<<(std::ostream &o, const Failure &failure)
|
|
|
|
{
|
|
|
|
using namespace std;
|
|
|
|
using namespace EscapeCodes;
|
|
|
|
return o << Phrases::Error << "Unable to parse arguments: " << TextAttribute::Reset << failure.what() << "\nSee --help for available commands."
|
|
|
|
<< endl;
|
|
|
|
}
|
|
|
|
|
2017-09-17 21:45:23 +02:00
|
|
|
} // namespace ApplicationUtilities
|