mirror of
https://github.com/davidallendj/gdpm.git
synced 2025-12-20 03:27:02 -07:00
Bump default godot version for search
- Change error code from `NONE` TO `IGNORE` - Added format function to utils - Implement version functions
This commit is contained in:
parent
d9a9ea6426
commit
d2a77fe28f
6 changed files with 46 additions and 15 deletions
|
|
@ -11,7 +11,7 @@
|
|||
namespace gdpm::constants::error{
|
||||
|
||||
enum class ec{
|
||||
NONE = 0,
|
||||
IGNORE = 0,
|
||||
UNKNOWN,
|
||||
UNKNOWN_COMMAND,
|
||||
UNKNOWN_ARGUMENT,
|
||||
|
|
@ -93,7 +93,7 @@ namespace gdpm{
|
|||
namespace ce = constants::error;
|
||||
class error {
|
||||
public:
|
||||
constexpr explicit error(ec code = ec::NONE, const string& message = "{default}"):
|
||||
constexpr explicit error(ec code = ec::IGNORE, const string& message = "{default}"):
|
||||
m_code(code),
|
||||
m_message(utils::replace_all(message, "{default}", ce::get_message(code)))
|
||||
{}
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ namespace gdpm::rest_api{
|
|||
int support;
|
||||
string user = "";
|
||||
string cost = "";
|
||||
string godot_version = "4.0";
|
||||
string godot_version = "4.3";
|
||||
int max_results = 500;
|
||||
int page;
|
||||
int offset;
|
||||
|
|
|
|||
|
|
@ -78,6 +78,11 @@ namespace gdpm::utils {
|
|||
return a;
|
||||
}
|
||||
|
||||
template <typename...Args>
|
||||
std::string format(std::string_view fmt, Args&&...args){
|
||||
return std::vformat(fmt, std::make_format_args(args...));
|
||||
}
|
||||
|
||||
bool to_bool(const std::string& s);
|
||||
std::vector<std::string> split_lines(const std::string& contents);
|
||||
std::string readfile(const std::string& path);
|
||||
|
|
@ -97,6 +102,7 @@ namespace gdpm::utils {
|
|||
std::string join(const std::vector<std::string>& target, const std::string& delimiter = ", ");
|
||||
std::string join(const std::unordered_map<std::string, std::string>& target, const std::string& prefix = "", const std::string& delimiter = "\n");
|
||||
std::string convert_size(long size);
|
||||
|
||||
// TODO: Add function to get size of decompressed zip
|
||||
|
||||
namespace json {
|
||||
|
|
|
|||
|
|
@ -1,14 +1,20 @@
|
|||
#pragma once
|
||||
|
||||
#include "error.hpp"
|
||||
#include "result.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace gdpm::version{
|
||||
struct version_context{
|
||||
int major;
|
||||
int minor;
|
||||
int patch;
|
||||
struct context{
|
||||
int major = 0;
|
||||
int minor = 0;
|
||||
int patch = 0;
|
||||
string commit = "";
|
||||
};
|
||||
|
||||
std::string to_string(const version_context& context);
|
||||
version_context to_version(const std::string& version);
|
||||
std::string to_string(const context& context);
|
||||
result_t<context> to_version(const std::string& version);
|
||||
bool is_valid_version_string(const std::string& version);
|
||||
}
|
||||
|
|
@ -343,7 +343,7 @@ namespace gdpm::config{
|
|||
error.set_message("Key `remote_sources` is not a JSON object.");
|
||||
return error;
|
||||
}
|
||||
error.set_code(ec::NONE);
|
||||
error.set_code(ec::IGNORE);
|
||||
return error;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,16 +1,35 @@
|
|||
|
||||
|
||||
#include "version.hpp"
|
||||
|
||||
#include <regex>
|
||||
|
||||
|
||||
namespace gdpm::version{
|
||||
|
||||
std::string to_string(const version_context& context){
|
||||
return std::string();
|
||||
void print(){
|
||||
|
||||
}
|
||||
|
||||
version_context to_version(const std::string& version){
|
||||
version_context v;
|
||||
string to_string(const context& c){
|
||||
return utils::format("{}.{}.{}", c.major, c.minor, c.patch);
|
||||
}
|
||||
|
||||
return v;
|
||||
result_t<context> to_version(const string& version){
|
||||
context v;
|
||||
|
||||
// check if string is valid
|
||||
if(!is_valid_version_string(version)){
|
||||
return result_t(context(), error(ec::IGNORE, "invalid version string"));
|
||||
}
|
||||
|
||||
// convert string to version context
|
||||
|
||||
|
||||
return result_t(v, error());
|
||||
}
|
||||
|
||||
bool is_valid_version_string(const string &version){
|
||||
return std::regex_match(version, std::regex("^(\\d+\\.)?(\\d+\\.)?(\\*|\\d+)$"));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue