6#include <kernel/util/arg_parser.hpp>
20 if(!custom_name.empty())
24 if(!long_flag.empty())
26 return long_flag.substr(2);
29 if(!short_flag.empty())
31 return short_flag.substr(1);
34 if(!property_path.empty())
39 if(!environment_variable.empty())
41 return environment_variable;
50 if(priority < incoming_priority)
55 arguments.push_back(s.
trim());
56 priority = incoming_priority;
58 else if(priority == incoming_priority)
62 arguments.push_back(s.
trim());
68 if(required && !set_by_user)
70 errors.push_back(
"Error: Parameter " +
name() +
" not given, but is required!");
80 catch(std::bad_any_cast& e)
84 catch(std::invalid_argument& e)
86 errors.push_back(
"Error: Validation of parameter " +
name() +
" failed with message: " + e.what());
90 for(
const auto& [core, condition] : needs)
94 XABORTM(
"Expired weak ptr to parameter core of " +
name());
97 auto ptr = core.lock();
99 if(set_by_user && condition(value))
101 if(!ptr->set_by_user)
104 "Error: Parameter " +
name() +
" needs parameter " + ptr->name() +
", but parameter " + ptr->name() +
105 " was not set by user");
113 if(arguments.empty())
126 if(type == ParameterType::collection_option)
128 String merged = std::accumulate(
132 [](
const String& a,
const String& b) {
return a +
" " + b; });
136 arguments.push_back(merged.
trim());
139 if(arguments.size() > 1)
141 errors.push_back(
"Error: Parameter " +
name() +
" was set multiple times. Only the first value is considered!");
147 "Error: No parser for parameter " +
name() +
148 ". Ensure operator>> is available for your type or set a custom parser!");
154 parser(value, arguments.front());
156 catch(std::bad_any_cast& e)
160 catch(std::invalid_argument& e)
162 errors.push_back(
"Error: Parsing for parameter " +
name() +
" failed with message: " + e.what());
169 value = default_value;
#define XABORTM(msg)
Abortion macro definition with custom message.
String name() const
Tries to create a user-readable name for this parameter.
void parse(std::deque< String > &errors)
Parse this parameter.
void validate(std::deque< String > &errors) const
Validate this parameter.
void reset()
Reset this parameter to default.
void add_argument(const String &s, int incoming_priority)
Add an argument to this parameter.
String class implementation.
String trim(const String &charset) const
Trims the string.