Fix fmt 10 breaking logging and changed printing format

This commit is contained in:
David Allen 2023-08-03 10:40:41 -06:00
parent 5bdc605f0b
commit 431be7914c
10 changed files with 114 additions and 130 deletions

View file

@ -3,52 +3,51 @@
#include "colors.hpp" #include "colors.hpp"
#include <string> #include <string>
// #define GDPM_ENABLE_COLORS 1
#if GDPM_ENABLE_COLORS == 1 #if GDPM_ENABLE_COLORS == 1
#define GDPM_COLOR_BLACK "\033[0;30m" constexpr const char *GDPM_COLOR_BLACK = "\033[0;30m";
#define GDPM_COLOR_BLUE "\033[0;34m" constexpr const char *GDPM_COLOR_BLUE = "\033[0;34m";
#define GDPM_COLOR_GREEN "\033[0;32m" constexpr const char *GDPM_COLOR_GREEN = "\033[0;32m";
#define GDPM_COLOR_CYAN "\033[0;36m" constexpr const char *GDPM_COLOR_CYAN = "\033[0;36m";
#define GDPM_COLOR_RED "\033[0;31m" constexpr const char *GDPM_COLOR_RED = "\033[0;31m";
#define GDPM_COLOR_PURPLE "\033[0;35m" constexpr const char *GDPM_COLOR_PURPLE = "\033[0;35m";
#define GDPM_COLOR_BROWN "\033[0;33m" constexpr const char *GDPM_COLOR_BROWN = "\033[0;33m";
#define GDPM_COLOR_GRAY "\033[0;37m" constexpr const char *GDPM_COLOR_GRAY = "\033[0;37m";
#define GDPM_COLOR_DARK_GRAY "\033[0;30m" constexpr const char *GDPM_COLOR_DARK_GRAY = "\033[0;30m";
#define GDPM_COLOR_LIGHT_BLUE "\033[0;34m" constexpr const char *GDPM_COLOR_LIGHT_BLUE = "\033[0;34m";
#define GDPM_COLOR_LIGHT_GREEN "\033[0;32m" constexpr const char *GDPM_COLOR_LIGHT_GREEN = "\033[0;32m";
#define GDPM_COLOR_LIGHT_CYAN "\033[0;36m" constexpr const char *GDPM_COLOR_LIGHT_CYAN = "\033[0;36m";
#define GDPM_COLOR_LIGHT_RED "\033[0;31m" constexpr const char *GDPM_COLOR_LIGHT_RED = "\033[0;31m";
#define GDPM_COLOR_LIGHT_PURPLE "\033[0;35m" constexpr const char *GDPM_COLOR_LIGHT_PURPLE = "\033[0;35m";
#define GDPM_COLOR_YELLOW "\033[0;33m" constexpr const char *GDPM_COLOR_YELLOW = "\033[0;33m";
#define GDPM_COLOR_WHITE "\033[0;37m" constexpr const char *GDPM_COLOR_WHITE = "\033[0;37m";
#define GDPM_COLOR_RESET GDPM_COLOR_WHITE constexpr const char *GDPM_COLOR_RESET = GDPM_COLOR_WHITE;
#else #else
#define GDPM_COLOR_BLACK "" constexpr const char *GDPM_COLOR_BLACK = "";
#define GDPM_COLOR_BLUE "" constexpr const char *GDPM_COLOR_BLUE = "";
#define GDPM_COLOR_GREEN "" constexpr const char *GDPM_COLOR_GREEN = "";
#define GDPM_COLOR_CYAN "" constexpr const char *GDPM_COLOR_CYAN = "";
#define GDPM_COLOR_RED "" constexpr const char *GDPM_COLOR_RED = "";
#define GDPM_COLOR_PURPLE "" constexpr const char *GDPM_COLOR_PURPLE = "";
#define GDPM_COLOR_BROWN "" constexpr const char *GDPM_COLOR_BROWN = "";
#define GDPM_COLOR_GRAY "" constexpr const char *GDPM_COLOR_GRAY = "";
#define GDPM_COLOR_DARK_GRAY "" constexpr const char *GDPM_COLOR_DARK_GRAY = "";
#define GDPM_COLOR_LIGHT_BLUE "" constexpr const char *GDPM_COLOR_LIGHT_BLUE = "";
#define GDPM_COLOR_LIGHT_GREEN "" constexpr const char *GDPM_COLOR_LIGHT_GREEN = "";
#define GDPM_COLOR_LIGHT_CYAN "" constexpr const char *GDPM_COLOR_LIGHT_CYAN = "";
#define GDPM_COLOR_LIGHT_RED "" constexpr const char *GDPM_COLOR_LIGHT_RED = "";
#define GDPM_COLOR_LIGHT_PURPLE "" constexpr const char *GDPM_COLOR_LIGHT_PURPLE = "";
#define GDPM_COLOR_YELLOW "" constexpr const char *GDPM_COLOR_YELLOW = "";
#define GDPM_COLOR_WHITE "" constexpr const char *GDPM_COLOR_WHITE = "";
#define GDPM_COLOR_RESET GDPM_COLOR_WHITE constexpr const char *GDPM_COLOR_RESET = GDPM_COLOR_WHITE;
#endif #endif
#define GDPM_COLOR_LOG_RESET GDPM_COLOR_WHITE constexpr const char *GDPM_COLOR_LOG_RESET = GDPM_COLOR_WHITE;
#define GDPM_COLOR_LOG_INFO GDPM_COLOR_LOG_RESET constexpr const char *GDPM_COLOR_LOG_INFO = GDPM_COLOR_LOG_RESET;
#define GDPM_COLOR_LOG_ERROR GDPM_COLOR_RED constexpr const char *GDPM_COLOR_LOG_ERROR = GDPM_COLOR_RED;
#define GDPM_COLOR_LOG_DEBUG GDPM_COLOR_YELLOW constexpr const char *GDPM_COLOR_LOG_DEBUG = GDPM_COLOR_YELLOW;
#define GDPM_COLOR_LOG_WARNING GDPM_COLOR_YELLOW constexpr const char *GDPM_COLOR_LOG_WARNING = GDPM_COLOR_YELLOW;
namespace gdpm::color{ namespace gdpm::color{
inline std::string from_string(const std::string& color_name){ inline std::string from_string(const std::string& color_name){

View file

@ -10,7 +10,7 @@
namespace gdpm::constants::error{ namespace gdpm::constants::error{
enum { enum class ec{
NONE = 0, NONE = 0,
UNKNOWN, UNKNOWN,
UNKNOWN_COMMAND, UNKNOWN_COMMAND,
@ -75,36 +75,40 @@ namespace gdpm::constants::error{
}; };
inline string get_message(int error_code) { inline string get_message(ec error_code) {
string message{}; string message{};
try{ message = messages[error_code]; } try{ message = messages[(int)error_code]; }
catch(const std::bad_alloc& e){ catch(const std::bad_alloc& e){
log::error("No default message for error code."); log::error("No default message for error code.");
} }
return message; return message;
} }
template <typename T>
inline T to(ec c){ return fmt::underlying_t<T>(c); }
}; };
namespace gdpm{ namespace gdpm{
namespace ec = constants::error; using ec = constants::error::ec;
namespace ce = constants::error;
class error { class error {
public: public:
constexpr explicit error(int code = 0, const string& message = "{default}"): constexpr explicit error(ec code = ec::NONE, const string& message = "{default}"):
m_code(code), m_code(code),
m_message(utils::replace_all(message, "{default}", ec::get_message(code))) m_message(utils::replace_all(message, "{default}", ce::get_message(code)))
{} {}
void set_code(int code) { m_code = code; } void set_code(ec code) { m_code = code; }
void set_message(const string& message) { m_message = message; } void set_message(const string& message) { m_message = message; }
int get_code() const { return m_code; } ec get_code() const { return m_code; }
string get_message() const { return m_message; } string get_message() const { return m_message; }
bool has_occurred() const { return m_code != 0; } bool has_occurred() const { return (int)m_code != 0; }
bool operator()(){ return has_occurred(); } bool operator()(){ return has_occurred(); }
private: private:
int m_code; ec m_code;
string m_message; string m_message;
}; };
@ -115,7 +119,7 @@ namespace gdpm{
set_prefix_if(std::format("[ERROR {}] ", utils::timestamp()), true); set_prefix_if(std::format("[ERROR {}] ", utils::timestamp()), true);
set_suffix_if("\n"); set_suffix_if("\n");
vlog( vlog(
fmt::format(GDPM_COLOR_LOG_ERROR "{}{}\n" GDPM_COLOR_LOG_RESET, prefix.contents, e.get_message()), fmt::format("{}{}{}{}\n", GDPM_COLOR_LOG_ERROR, prefix.contents, e.get_message(), GDPM_COLOR_LOG_RESET),
fmt::make_format_args(prefix.contents, e.get_message()) fmt::make_format_args(prefix.contents, e.get_message())
); );
#endif #endif
@ -130,7 +134,7 @@ namespace gdpm{
return e; return e;
} }
static constexpr gdpm::error error_rc(int code, const string& message = "{default}"){ static constexpr gdpm::error error_rc(ec code, const string& message = "{default}"){
return error_rc(gdpm::error(code, message)); return error_rc(gdpm::error(code, message));
} }
} }

View file

@ -94,7 +94,7 @@ namespace gdpm::log
set_prefix_if(fmt::format( get_info_prefix(), utils::timestamp()), true); set_prefix_if(fmt::format( get_info_prefix(), utils::timestamp()), true);
set_suffix_if("\n"); set_suffix_if("\n");
vlog( vlog(
fmt::format(GDPM_COLOR_LOG_INFO "{}{}{}" GDPM_COLOR_LOG_RESET, prefix.contents, format, suffix), fmt::format("{}{}{}{}{}", GDPM_COLOR_LOG_INFO, prefix.contents, format, suffix, GDPM_COLOR_LOG_RESET),
fmt::make_format_args(args...) fmt::make_format_args(args...)
); );
#endif #endif
@ -108,7 +108,7 @@ namespace gdpm::log
set_prefix_if(fmt::format(get_info_prefix(), utils::timestamp()), true); set_prefix_if(fmt::format(get_info_prefix(), utils::timestamp()), true);
set_suffix_if("", true); set_suffix_if("", true);
vlog( vlog(
fmt::format(GDPM_COLOR_LOG_INFO "{}{}{}" GDPM_COLOR_LOG_RESET, prefix.contents, format, suffix), fmt::format("{}{}{}{}{}", GDPM_COLOR_LOG_INFO, prefix.contents, format, suffix, GDPM_COLOR_LOG_RESET),
fmt::make_format_args(args...) fmt::make_format_args(args...)
); );
#endif #endif
@ -122,7 +122,7 @@ namespace gdpm::log
set_prefix_if(std::format(get_error_prefix(), utils::timestamp()), true); set_prefix_if(std::format(get_error_prefix(), utils::timestamp()), true);
set_suffix_if("\n"); set_suffix_if("\n");
vlog( vlog(
fmt::format(GDPM_COLOR_LOG_ERROR "{}{}{}" GDPM_COLOR_LOG_RESET, prefix.contents, format, suffix), std::format("{}{}{}{}{}", GDPM_COLOR_LOG_ERROR, prefix.contents, format, suffix, GDPM_COLOR_LOG_RESET),
fmt::make_format_args(args...) fmt::make_format_args(args...)
); );
#endif #endif
@ -136,7 +136,7 @@ namespace gdpm::log
set_prefix_if(std::format(get_debug_prefix(), utils::timestamp()), true); set_prefix_if(std::format(get_debug_prefix(), utils::timestamp()), true);
set_suffix_if("\n"); set_suffix_if("\n");
vlog( vlog(
fmt::format(GDPM_COLOR_LOG_DEBUG "{}{}{}" GDPM_COLOR_LOG_RESET, prefix.contents, format, suffix), std::format("{}{}{}", GDPM_COLOR_LOG_DEBUG, prefix.contents, format, suffix, GDPM_COLOR_LOG_RESET),
fmt::make_format_args(args...) fmt::make_format_args(args...)
); );
#endif #endif
@ -150,7 +150,7 @@ namespace gdpm::log
set_prefix_if(std::format(get_warning_prefix(), utils::timestamp()), true); set_prefix_if(std::format(get_warning_prefix(), utils::timestamp()), true);
set_suffix_if("\n"); set_suffix_if("\n");
vlog( vlog(
fmt::format(GDPM_COLOR_LOG_WARNING "{}{}{}" GDPM_COLOR_LOG_RESET, prefix.contents, format, suffix), std::format("{}{}{}", GDPM_COLOR_LOG_WARNING, prefix.contents, format, suffix, GDPM_COLOR_LOG_RESET),
fmt::make_format_args(args...) fmt::make_format_args(args...)
); );
#endif #endif
@ -160,7 +160,7 @@ namespace gdpm::log
template <typename S, typename...Args> template <typename S, typename...Args>
static constexpr void print(const S& format, Args&&...args){ static constexpr void print(const S& format, Args&&...args){
vlog( vlog(
fmt::format("{}", format), std::format("{}", format),
fmt::make_format_args(args...) fmt::make_format_args(args...)
); );
} }
@ -168,7 +168,7 @@ namespace gdpm::log
template <typename S = string, typename...Args> template <typename S = string, typename...Args>
static constexpr void println(const S& format, Args&&...args){ static constexpr void println(const S& format, Args&&...args){
vlog( vlog(
fmt::format("{}\n", format), std::format("{}\n", format),
fmt::make_format_args(args...) fmt::make_format_args(args...)
); );
} }

View file

@ -173,7 +173,7 @@ namespace gdpm::cache{
sql += "COMMIT;\n"; sql += "COMMIT;\n";
rc = sqlite3_exec(db, sql.c_str(), callback, (void*)&p_vector, &errmsg); rc = sqlite3_exec(db, sql.c_str(), callback, (void*)&p_vector, &errmsg);
if(rc != SQLITE_OK){ if(rc != SQLITE_OK){
error error(constants::error::SQLITE_ERR, std::format( error error(ec::SQLITE_ERR, std::format(
"cache::get_package_info_by_id::sqlite3_exec(): {}", errmsg "cache::get_package_info_by_id::sqlite3_exec(): {}", errmsg
)); ));
sqlite3_free(errmsg); sqlite3_free(errmsg);

View file

@ -262,8 +262,7 @@ namespace gdpm::config{
else if(property == "verbosity") config.verbose = std::stoi(value); else if(property == "verbosity") config.verbose = std::stoi(value);
else if(property == "style") config.style = to_style(value); else if(property == "style") config.style = to_style(value);
else{ else{
return log::error_rc(error( return log::error_rc(error(ec::INVALID_CONFIG,
constants::error::INVALID_CONFIG,
"Could not find property" "Could not find property"
)); ));
} }
@ -331,7 +330,7 @@ namespace gdpm::config{
error validate(const rapidjson::Document& doc){ error validate(const rapidjson::Document& doc){
error error(constants::error::INVALID_CONFIG, ""); error error(ec::INVALID_CONFIG, "");
if(!doc.IsObject()){ if(!doc.IsObject()){
error.set_message("Document is not a JSON object."); error.set_message("Document is not a JSON object.");
return error; return error;
@ -344,7 +343,7 @@ namespace gdpm::config{
error.set_message("Key `remote_sources` is not a JSON object."); error.set_message("Key `remote_sources` is not a JSON object.");
return error; return error;
} }
error.set_code(constants::error::NONE); error.set_code(ec::NONE);
return error; return error;
} }

View file

@ -4,6 +4,7 @@
#include "log.hpp" #include "log.hpp"
#include "error.hpp" #include "error.hpp"
#include <atomic> #include <atomic>
#include <cstdint>
#include <curl/curl.h> #include <curl/curl.h>
#include <curl/easy.h> #include <curl/easy.h>
#include <curl/multi.h> #include <curl/multi.h>
@ -74,9 +75,7 @@ namespace gdpm::http{
curl_slist_free_all(list); curl_slist_free_all(list);
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &r.code); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &r.code);
if(res != CURLE_OK && params.verbose > 0) if(res != CURLE_OK && params.verbose > 0)
log::error(ec::LIBCURL_ERR, log::error("http::context::request::curl_easy_perform(): {}", (long)curl_easy_strerror(res));
std::format("http::context::request::curl_easy_perform(): {}", curl_easy_strerror(res))
);
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
} }
@ -91,7 +90,7 @@ namespace gdpm::http{
const http::request& params const http::request& params
){ ){
if(cm == nullptr){ if(cm == nullptr){
log::error(error(PRECONDITION_FAILED, log::error(error(ec::PRECONDITION_FAILED,
"http::multi::make_downloads(): multi client not initialized.") "http::multi::make_downloads(): multi client not initialized.")
); );
} }
@ -173,7 +172,8 @@ namespace gdpm::http{
log::println("transfers left: {}", transfers_left); log::println("transfers left: {}", transfers_left);
cres = curl_multi_remove_handle(cm, eh); cres = curl_multi_remove_handle(cm, eh);
if(cres != CURLM_OK){ if(cres != CURLM_OK){
log::error("http::context::execute(): curl_multi_remove_handle() returned error {}", cres); log::error(error(ec::LIBCURL_ERR,
std::format("http::context::execute(): curl_multi_remove_handle() returned error {}", (int)cres)));
} }
curl_easy_cleanup(eh); curl_easy_cleanup(eh);
transfers_left -= 1; transfers_left -= 1;
@ -190,13 +190,15 @@ namespace gdpm::http{
if(transfers_left){ if(transfers_left){
cres = curl_multi_wait(cm, NULL, 0, params.timeout, NULL); cres = curl_multi_wait(cm, NULL, 0, params.timeout, NULL);
if(cres != CURLM_OK){ if(cres != CURLM_OK){
log::error("http::context::execute(): curl_multi_wait() returned an error {}", cres); log::error(error(ec::LIBCURL_ERR,
std::format("http::context::execute(): curl_multi_wait() returned an error {}", (int)cres)));
} }
} }
}while(transfers_left); }while(transfers_left);
cres = curl_multi_cleanup(cm); cres = curl_multi_cleanup(cm);
if(cres != CURLM_OK){ if(cres != CURLM_OK){
log::error("http::context::execute(): curl_multi_cleanup() returned an error {}", cres); log::error(error(ec::LIBCURL_ERR,
std::format("http::context::execute(): curl_multi_cleanup() returned an error {}", (int)cres)));
} }
return responses(); return responses();
} }
@ -233,9 +235,7 @@ namespace gdpm::http{
/* Get response code, process error, save data, and close file. */ /* Get response code, process error, save data, and close file. */
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &r.code); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &r.code);
if(res != CURLE_OK && params.verbose > 0){ if(res != CURLE_OK && params.verbose > 0){
log::error(ec::LIBCURL_ERR, log::error("http::context::download_file::curl_easy_perform() failed: {}", curl_easy_strerror(res));
std::format("http::context::download_file::curl_easy_perform() failed: {}", curl_easy_strerror(res))
);
} }
fclose(fp); fclose(fp);
} }
@ -285,9 +285,7 @@ namespace gdpm::http{
cres = curl_multi_add_handle(cm, curl); cres = curl_multi_add_handle(cm, curl);
curl_slist_free_all(list); curl_slist_free_all(list);
if(cres != CURLM_OK){ if(cres != CURLM_OK){
log::error(ec::LIBCURL_ERR, log::error("http::context::make_downstd::format(loads(): {}", curl_multi_strerror(cres));
std::format("http::context::make_downloads(): {}", curl_multi_strerror(cres))
);
} }
} }
transfers_index += 1; transfers_index += 1;
@ -329,7 +327,7 @@ namespace gdpm::http{
} }
cres = curl_multi_remove_handle(cm, eh); cres = curl_multi_remove_handle(cm, eh);
if(cres != CURLM_OK){ if(cres != CURLM_OK){
log::error("http::context::execute(): curl_multi_remove_handle() returned error {}", cres); log::error("http::context::execute(): curl_multi_remove_handle() returned error {}", (int)cres);
} }
transfers_left -= 1; transfers_left -= 1;
curl_easy_cleanup(eh); curl_easy_cleanup(eh);
@ -348,13 +346,13 @@ namespace gdpm::http{
if(transfers_left){ if(transfers_left){
cres = curl_multi_wait(cm, NULL, 0, params.timeout, NULL); cres = curl_multi_wait(cm, NULL, 0, params.timeout, NULL);
if(cres != CURLM_OK){ if(cres != CURLM_OK){
log::error("http::context::execute(): curl_multi_wait() returned an error {}", cres); log::error("http::context::execute(): curl_multi_wait() returned an error {}", (int)cres);
} }
} }
}while(transfers_left); }while(transfers_left);
cres = curl_multi_cleanup(cm); cres = curl_multi_cleanup(cm);
if(cres != CURLM_OK){ if(cres != CURLM_OK){
log::error("http::context::execute(): curl_multi_cleanup() returned an error {}", cres); log::error("http::context::execute(): curl_multi_cleanup() returned an error {}", (int)cres);
} }
return responses(); return responses();
} }

View file

@ -219,7 +219,7 @@ namespace gdpm::package{
error error = cache::update_package_info(p_cache); error error = cache::update_package_info(p_cache);
if(error.has_occurred()){ if(error.has_occurred()){
string prefix = std::format(log::get_error_prefix(), utils::timestamp()); string prefix = std::format(log::get_error_prefix(), utils::timestamp());
log::println(GDPM_COLOR_LOG_ERROR"\n{}{}" GDPM_COLOR_RESET, prefix, error.get_message()); log::println("\n{}{}{}{}", GDPM_COLOR_LOG_ERROR, prefix, error.get_message(), GDPM_COLOR_RESET);
return error; return error;
} }
if(config.clean_temporary){ if(config.clean_temporary){
@ -287,8 +287,7 @@ namespace gdpm::package{
if(is_missing_data){ if(is_missing_data){
doc = rest_api::get_asset(url, p.asset_id, rest_api_params); doc = rest_api::get_asset(url, p.asset_id, rest_api_params);
if(doc.HasParseError() || doc.IsNull()){ if(doc.HasParseError() || doc.IsNull()){
return log::error_rc(error( return log::error_rc(error(ec::JSON_ERR,
constants::error::JSON_ERR,
std::format("Error parsing JSON: {}", GetParseError_En(doc.GetParseError())) std::format("Error parsing JSON: {}", GetParseError_En(doc.GetParseError()))
)); ));
} }
@ -344,8 +343,7 @@ namespace gdpm::package{
if(response.code == http::OK){ if(response.code == http::OK){
log::println("Done."); log::println("Done.");
}else{ }else{
return log::error_rc(error( return log::error_rc(error(ec::HTTP_RESPONSE_ERR,
constants::error::HTTP_RESPONSE_ERR,
std::format("HTTP Error: {}", response.code) std::format("HTTP Error: {}", response.code)
)); ));
} }
@ -710,8 +708,7 @@ namespace gdpm::package{
using namespace std::filesystem; using namespace std::filesystem;
if(params.paths.empty()){ if(params.paths.empty()){
return log::error_rc(error( return log::error_rc(error(ec::MALFORMED_PATH,
constants::error::MALFORMED_PATH,
"Path is required" "Path is required"
)); ));
} }
@ -721,8 +718,7 @@ namespace gdpm::package{
info_list p_found = {}; info_list p_found = {};
info_list p_cache = r_cache.unwrap_unsafe(); info_list p_cache = r_cache.unwrap_unsafe();
if(p_cache.empty()){ if(p_cache.empty()){
return log::error_rc(error( return log::error_rc(error(ec::NOT_FOUND,
constants::error::NOT_FOUND,
"Could not find any packages to link in cache." "Could not find any packages to link in cache."
)); ));
} }
@ -735,8 +731,7 @@ namespace gdpm::package{
} }
if(p_found.empty()){ if(p_found.empty()){
return log::error_rc(error( return log::error_rc(error(ec::NO_PACKAGE_FOUND,
constants::error::NO_PACKAGE_FOUND,
"No packages found to link." "No packages found to link."
)); ));
} }
@ -755,7 +750,7 @@ namespace gdpm::package{
std::filesystem::create_directory_symlink(target, symlink_path, ec); std::filesystem::create_directory_symlink(target, symlink_path, ec);
if(ec){ if(ec){
log::error(error( log::error(error(
constants::error::STD_ERR, ec::STD_ERR,
std::format("Could not create symlink: {}", ec.message()) std::format("Could not create symlink: {}", ec.message())
)); ));
} }
@ -774,8 +769,7 @@ namespace gdpm::package{
if(params.paths.empty()){ if(params.paths.empty()){
return log::error_rc(error( return log::error_rc(error(
constants::error::MALFORMED_PATH, ec::MALFORMED_PATH, "Path is required"
"Path is required"
)); ));
} }
@ -785,8 +779,7 @@ namespace gdpm::package{
/* Check for installed packages to clone */ /* Check for installed packages to clone */
if(p_cache.empty()){ if(p_cache.empty()){
return log::error_rc(error( return log::error_rc(error(ec::NO_PACKAGE_FOUND,
constants::error::NO_PACKAGE_FOUND,
"Could not find any packages to clone in cache." "Could not find any packages to clone in cache."
)); ));
} }
@ -804,8 +797,7 @@ namespace gdpm::package{
} }
if(p_found.empty()){ if(p_found.empty()){
return log::error_rc(error( return log::error_rc(error(ec::NO_PACKAGE_FOUND,
constants::error::NO_PACKAGE_FOUND,
"No packages found to clone." "No packages found to clone."
)); ));
} }
@ -913,20 +905,18 @@ namespace gdpm::package{
void print_list(const info_list& packages){ void print_list(const info_list& packages){
for(const auto& p : packages){ for(const auto& p : packages){
log::println( log::println(
GDPM_COLOR_BLUE"{}/" "{}{}/{}/{}/{} {}\n\tv{} {} Godot {} {}{}",
GDPM_COLOR_RESET "{}/{}/{} " GDPM_COLOR_GREEN, p.support_level,
GDPM_COLOR_GREEN "v{} "
GDPM_COLOR_CYAN "{} "
GDPM_COLOR_RESET "Godot {}, {}",
p.support_level,
p.category, p.category,
p.author, p.author,
p.title, p.title,
GDPM_COLOR_CYAN,
p.version, p.version,
p.modify_date, p.modify_date,
// p.asset_id, // p.asset_id,
p.godot_version, p.godot_version,
p.cost p.cost,
GDPM_COLOR_RESET
); );
} }
} }
@ -935,21 +925,18 @@ namespace gdpm::package{
void print_list(const rapidjson::Document& json){ void print_list(const rapidjson::Document& json){
for(const auto& o : json["result"].GetArray()){ for(const auto& o : json["result"].GetArray()){
log::println( log::println(
GDPM_COLOR_BLUE"{}/" "{}{}/{}/{}/{} {}\n\tv{} {} Godot {} {}{}",
GDPM_COLOR_CYAN "{}/" GDPM_COLOR_GREEN, o["support_level"].GetString(),
GDPM_COLOR_RESET "{}/{} "
GDPM_COLOR_GREEN "v{} "
GDPM_COLOR_CYAN "{} "
GDPM_COLOR_RESET "Godot {}, {}",
o["support_level"] .GetString(),
utils::to_lower(o["category"].GetString()), utils::to_lower(o["category"].GetString()),
o["author"] .GetString(), o["author"].GetString(),
o["title"] .GetString(), o["title"].GetString(),
o["version_string"] .GetString(), GDPM_COLOR_CYAN,
o["modify_date"] .GetString(), o["version_string"].GetString(),
// o["asset_id"] .GetString(), o["modify_date"].GetString(),
o["godot_version"] .GetString(), // o["asset_id"].GetString(),
o["cost"] .GetString() o["godot_version"].GetString(),
o["cost"].GetString(),
GDPM_COLOR_RESET
); );
} }
} }

View file

@ -16,8 +16,7 @@ namespace gdpm::remote{
/* Check if enough args were provided. */ /* Check if enough args were provided. */
log::println("arg count: {}\nargs: {}", args.size(), utils::join(args)); log::println("arg count: {}\nargs: {}", args.size(), utils::join(args));
if (args.size() < 2){ if (args.size() < 2){
return error( return error(ec::INVALID_ARG_COUNT,
constants::error::INVALID_ARG_COUNT,
"Requires a remote name and url argument" "Requires a remote name and url argument"
); );
} }
@ -35,8 +34,7 @@ namespace gdpm::remote{
){ ){
log::println("arg count: {}\nargs: {}", args.size(), utils::join(args)); log::println("arg count: {}\nargs: {}", args.size(), utils::join(args));
if(args.size() < 1){ if(args.size() < 1){
return error( return error(ec::INVALID_ARG_COUNT,
constants::error::INVALID_ARG_COUNT,
"Requires at least one remote name argument" "Requires at least one remote name argument"
); );
} }

View file

@ -242,9 +242,8 @@ namespace gdpm::rest_api{
const string_list& filters const string_list& filters
){ ){
if(urls.size() == asset_ids.size() && urls.size() == filters.size()){ if(urls.size() == asset_ids.size() && urls.size() == filters.size()){
log::error(ec::ASSERTION_FAILED, log::error(error(ec::ASSERTION_FAILED,
"multi::get_assets(): urls.size() != filters.size()" "multi::get_assets(): urls.size() != filters.size()"));
);
} }
http::context http(4); http::context http(4);
http::request params; http::request params;

View file

@ -80,8 +80,8 @@ TEST_CASE("Test configuration functions"){
std::string json = config::to_json(config); std::string json = config::to_json(config);
error error_save = config::save(config.path, config); error error_save = config::save(config.path, config);
CHECK(error_save.get_code() == 0); CHECK((int)error_save.get_code() == 0);
error error_load = config::load(config.path, config); error error_load = config::load(config.path, config);
CHECK(error_load.get_code() == 0); CHECK((int)error_load.get_code() == 0);
} }