diff --git a/Hazelnupp.vpp b/Hazelnupp.vpp index 80f2841..f946694 100644 Binary files a/Hazelnupp.vpp and b/Hazelnupp.vpp differ diff --git a/Hazelnupp/Hazelnupp.cpp b/Hazelnupp/Hazelnupp.cpp index 2c07737..eb4caec 100644 --- a/Hazelnupp/Hazelnupp.cpp +++ b/Hazelnupp/Hazelnupp.cpp @@ -62,13 +62,23 @@ void Hazelnupp::Parse(const int argc, const char* const* argv) } catch (const HazelnuppConstraintTypeMissmatch& hctm) { - std::cerr << "Fatal error: Command-line parameter value-type mismatch at \"" << hctm.What() << "\"!"; - quick_exit(-1009); + 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) { - std::cerr << "Fatal error: Missing required command-line parameter \"" << hctm.What() << "\"!"; - quick_exit(-1010); + 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& 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); diff --git a/Hazelnupp/Hazelnupp.h b/Hazelnupp/Hazelnupp.h index 96e0e95..2e44b4d 100644 --- a/Hazelnupp/Hazelnupp.h +++ b/Hazelnupp/Hazelnupp.h @@ -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 constraints; std::vector rawArgs; + + //! If set to true, Hazelnupp will crash the application with output to stderr when an exception is thrown whilst parsing. + bool crashOnFail = true; };