Slight modifications, and added unit tests
This commit is contained in:
@@ -320,25 +320,35 @@ void Hazelnp::Hazelnupp::RegisterDescription(const std::string& parameter, const
|
||||
return;
|
||||
}
|
||||
|
||||
const std::string Hazelnp::Hazelnupp::GetDescription(const std::string& parameter) const
|
||||
std::string Hazelnp::Hazelnupp::GetDescription(const std::string& parameter) const
|
||||
{
|
||||
// Do we already have a description for this parameter?
|
||||
const auto par = parameterDescriptions.find(parameter);
|
||||
if (par == parameterDescriptions.end())
|
||||
if (!HasDescription(parameter))
|
||||
// No? Then return ""
|
||||
return "";
|
||||
|
||||
// We do? Then return it
|
||||
return par->second;
|
||||
return parameterDescriptions.find(parameter)->second;
|
||||
}
|
||||
|
||||
void Hazelnp::Hazelnupp::ClearDescription(const std::string& parameter)
|
||||
bool Hazelnupp::HasDescription(const std::string& parameter) const
|
||||
{
|
||||
return parameterDescriptions.find(parameter) != parameterDescriptions.end();
|
||||
}
|
||||
|
||||
void Hazelnupp::ClearDescription(const std::string& parameter)
|
||||
{
|
||||
// This will just do nothing if the entry does not exist
|
||||
parameterDescriptions.erase(parameter);
|
||||
return;
|
||||
}
|
||||
|
||||
void Hazelnp::Hazelnupp::ClearDescriptions()
|
||||
{
|
||||
parameterDescriptions.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
std::string Hazelnupp::GenerateDocumentation() const
|
||||
{
|
||||
std::stringstream ss;
|
||||
@@ -482,6 +492,17 @@ void Hazelnupp::ApplyConstraints()
|
||||
return;
|
||||
}
|
||||
|
||||
ParamConstraint Hazelnupp::GetConstraint(const std::string& parameter) const
|
||||
{
|
||||
return constraints.find(parameter)->second;
|
||||
}
|
||||
|
||||
void Hazelnupp::ClearConstraint(const std::string& parameter)
|
||||
{
|
||||
constraints.erase(parameter);
|
||||
return;
|
||||
}
|
||||
|
||||
const std::string& Hazelnupp::GetExecutableName() const
|
||||
{
|
||||
return executableName;
|
||||
@@ -502,8 +523,11 @@ void Hazelnupp::RegisterAbbreviation(const std::string& abbrev, const std::strin
|
||||
return;
|
||||
}
|
||||
|
||||
const std::string& Hazelnupp::GetAbbreviation(const std::string& abbrev) const
|
||||
std::string Hazelnupp::GetAbbreviation(const std::string& abbrev) const
|
||||
{
|
||||
if (!HasAbbreviation(abbrev))
|
||||
return "";
|
||||
|
||||
return abbreviations.find(abbrev)->second;
|
||||
}
|
||||
|
||||
@@ -512,6 +536,12 @@ bool Hazelnupp::HasAbbreviation(const std::string& abbrev) const
|
||||
return abbreviations.find(abbrev) != abbreviations.end();
|
||||
}
|
||||
|
||||
void Hazelnupp::ClearAbbreviation(const std::string& abbrevation)
|
||||
{
|
||||
abbreviations.erase(abbrevation);
|
||||
return;
|
||||
}
|
||||
|
||||
void Hazelnupp::ClearAbbreviations()
|
||||
{
|
||||
abbreviations.clear();
|
||||
|
@@ -32,18 +32,29 @@ namespace Hazelnp
|
||||
//! Will register an abbreviation (like -f for --force)
|
||||
void RegisterAbbreviation(const std::string& abbrev, const std::string& target);
|
||||
|
||||
//! Will return the long form of an abbreviation (like --force for -f)
|
||||
const std::string& GetAbbreviation(const std::string& abbrev) const;
|
||||
//! Will return the long form of an abbreviation (like --force for -f)
|
||||
//! Returns "" if no match is found
|
||||
std::string GetAbbreviation(const std::string& abbrev) const;
|
||||
|
||||
//! Will check wether or not an abbreviation is registered
|
||||
bool HasAbbreviation(const std::string& abbrev) const;
|
||||
|
||||
//! Will delete the abbreviation for a given parameter.
|
||||
//! IMPORTANT: This parameter is the abbreviation! Not the long form!
|
||||
void ClearAbbreviation(const std::string& abbrevation);
|
||||
|
||||
//! Will delete all abbreviations
|
||||
void ClearAbbreviations();
|
||||
|
||||
//! Will register parameter constraints
|
||||
void RegisterConstraints(const std::vector<ParamConstraint>& constraints);
|
||||
|
||||
//! Will return the constraint information for a specific parameter
|
||||
ParamConstraint GetConstraint(const std::string& parameter) const;
|
||||
|
||||
//! Will the constraint of a specific parameter
|
||||
void ClearConstraint(const std::string& parameter);
|
||||
|
||||
//! Will delete all constraints
|
||||
void ClearConstraints();
|
||||
|
||||
@@ -72,11 +83,17 @@ namespace Hazelnp
|
||||
|
||||
//! Will return a short description for a parameter, if it exists.
|
||||
//! Empty string if it does not exist.
|
||||
const std::string GetDescription(const std::string& parameter) const;
|
||||
std::string GetDescription(const std::string& parameter) const;
|
||||
|
||||
//! Returns whether or not a given parameter has a registered description
|
||||
bool HasDescription(const std::string& parameter) const;
|
||||
|
||||
//! Will delete the description of a parameter if it exists.
|
||||
void ClearDescription(const std::string& parameter);
|
||||
|
||||
//! Will delete all parameter descriptions
|
||||
void ClearDescriptions();
|
||||
|
||||
//! Will generate a text-based documentation suited to show the user, for example on --help.
|
||||
std::string GenerateDocumentation() const;
|
||||
|
||||
@@ -112,6 +129,7 @@ namespace Hazelnp
|
||||
std::vector<std::string> rawArgs;
|
||||
|
||||
//! Short descriptions for parameters
|
||||
//! First member is the abbreviation
|
||||
std::unordered_map<std::string, std::string> parameterDescriptions;
|
||||
|
||||
//! A brief description of the application to be added to the generated documentation. Optional.
|
||||
|
Reference in New Issue
Block a user