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.
@ -62,13 +62,23 @@ void Hazelnupp::Parse(const int argc, const char* const* argv)
|
|||||||
}
|
}
|
||||||
catch (const HazelnuppConstraintTypeMissmatch& hctm)
|
catch (const HazelnuppConstraintTypeMissmatch& hctm)
|
||||||
{
|
{
|
||||||
std::cerr << "Fatal error: Command-line parameter value-type mismatch at \"" << hctm.What() << "\"!";
|
if (crashOnFail)
|
||||||
quick_exit(-1009);
|
{
|
||||||
|
std::cerr << "Fatal error: Command-line parameter value-type mismatch at \"" << hctm.What() << "\"!";
|
||||||
|
quick_exit(-1009);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw hctm; // yeet
|
||||||
}
|
}
|
||||||
catch (const HazelnuppConstraintMissingValue& hctm)
|
catch (const HazelnuppConstraintMissingValue& hctm)
|
||||||
{
|
{
|
||||||
std::cerr << "Fatal error: Missing required command-line parameter \"" << hctm.What() << "\"!";
|
if (crashOnFail)
|
||||||
quick_exit(-1010);
|
{
|
||||||
|
std::cerr << "Fatal error: Missing required command-line parameter \"" << hctm.What() << "\"!";
|
||||||
|
quick_exit(-1010);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw hctm; // yeet
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -259,6 +269,11 @@ Value* Hazelnupp::ParseValue(const std::vector<std::string>& values, const Param
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Hazelnupp::GetCrashOnFail() const
|
||||||
|
{
|
||||||
|
return crashOnFail;
|
||||||
|
}
|
||||||
|
|
||||||
void Hazelnupp::ApplyConstraints()
|
void Hazelnupp::ApplyConstraints()
|
||||||
{
|
{
|
||||||
// Enforce required parameters / default values
|
// Enforce required parameters / default values
|
||||||
@ -356,6 +371,12 @@ void Hazelnupp::ClearConstraints()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Hazelnupp::SetCrashOnFail(bool crashOnFail)
|
||||||
|
{
|
||||||
|
this->crashOnFail = crashOnFail;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const ParamConstraint* Hazelnupp::GetConstraintForKey(const std::string& key) const
|
const ParamConstraint* Hazelnupp::GetConstraintForKey(const std::string& key) const
|
||||||
{
|
{
|
||||||
const auto constraint = constraints.find(key);
|
const auto constraint = constraints.find(key);
|
||||||
|
@ -43,6 +43,13 @@ public:
|
|||||||
//! Will delete all constraints
|
//! Will delete all constraints
|
||||||
void ClearConstraints();
|
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:
|
private:
|
||||||
//! Will translate the c-like args to an std::vector
|
//! Will translate the c-like args to an std::vector
|
||||||
void PopulateRawArgs(const int argc, const char* const* argv);
|
void PopulateRawArgs(const int argc, const char* const* argv);
|
||||||
@ -72,4 +79,7 @@ private:
|
|||||||
std::unordered_map<std::string, ParamConstraint> constraints;
|
std::unordered_map<std::string, ParamConstraint> constraints;
|
||||||
|
|
||||||
std::vector<std::string> rawArgs;
|
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