Implemented a SetCrashOnFail(bool) method for Hazelnupp
This commit is contained in:
parent
33200477a6
commit
dbc02fab2e
BIN
Hazelnupp.vpp
BIN
Hazelnupp.vpp
Binary file not shown.
@ -61,15 +61,25 @@ void Hazelnupp::Parse(const int argc, const char* const* argv)
|
||||
ApplyConstraints();
|
||||
}
|
||||
catch (const HazelnuppConstraintTypeMissmatch& hctm)
|
||||
{
|
||||
if (crashOnFail)
|
||||
{
|
||||
std::cerr << "Fatal error: Command-line parameter value-type mismatch at \"" << hctm.What() << "\"!";
|
||||
quick_exit(-1009);
|
||||
}
|
||||
else
|
||||
throw hctm; // yeet
|
||||
}
|
||||
catch (const HazelnuppConstraintMissingValue& hctm)
|
||||
{
|
||||
if (crashOnFail)
|
||||
{
|
||||
std::cerr << "Fatal error: Missing required command-line parameter \"" << hctm.What() << "\"!";
|
||||
quick_exit(-1010);
|
||||
}
|
||||
else
|
||||
throw hctm; // yeet
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@ -259,6 +269,11 @@ Value* Hazelnupp::ParseValue(const std::vector<std::string>& values, const Param
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool Hazelnupp::GetCrashOnFail() const
|
||||
{
|
||||
return crashOnFail;
|
||||
}
|
||||
|
||||
void Hazelnupp::ApplyConstraints()
|
||||
{
|
||||
// Enforce required parameters / default values
|
||||
@ -356,6 +371,12 @@ void Hazelnupp::ClearConstraints()
|
||||
return;
|
||||
}
|
||||
|
||||
void Hazelnupp::SetCrashOnFail(bool crashOnFail)
|
||||
{
|
||||
this->crashOnFail = crashOnFail;
|
||||
return;
|
||||
}
|
||||
|
||||
const ParamConstraint* Hazelnupp::GetConstraintForKey(const std::string& key) const
|
||||
{
|
||||
const auto constraint = constraints.find(key);
|
||||
|
@ -43,6 +43,13 @@ public:
|
||||
//! Will delete all constraints
|
||||
void ClearConstraints();
|
||||
|
||||
//! Sets whether to crash the application, and print to stderr, when an exception is
|
||||
//! raised whilst parsing, or not.
|
||||
void SetCrashOnFail(bool crashOnFail);
|
||||
|
||||
//! Gets whether the application crashes on an exception whilst parsing, and prints to stderr.
|
||||
bool GetCrashOnFail() const;
|
||||
|
||||
private:
|
||||
//! Will translate the c-like args to an std::vector
|
||||
void PopulateRawArgs(const int argc, const char* const* argv);
|
||||
@ -72,4 +79,7 @@ private:
|
||||
std::unordered_map<std::string, ParamConstraint> constraints;
|
||||
|
||||
std::vector<std::string> rawArgs;
|
||||
|
||||
//! If set to true, Hazelnupp will crash the application with output to stderr when an exception is thrown whilst parsing.
|
||||
bool crashOnFail = true;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user