mirror of
https://github.com/davidallendj/gdpm.git
synced 2025-12-19 19:17:01 -07:00
Refactored, simplified, and removed code; replaced cli header lib
- Reinitialized submodules - Slightly restructed project - Added more options to `compile.sh` script - Added more utility functions
This commit is contained in:
parent
d34243db74
commit
e48c54aa40
27 changed files with 564 additions and 3232 deletions
1
include/clipp.h
Symbolic link
1
include/clipp.h
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../modules/clipp/include/clipp.h
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "constants.hpp"
|
||||
#include "error.hpp"
|
||||
#include "package.hpp"
|
||||
|
||||
#include <rapidjson/document.h>
|
||||
#include <string>
|
||||
|
|
@ -9,27 +10,40 @@
|
|||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
|
||||
namespace gdpm::package{
|
||||
struct info;
|
||||
struct params;
|
||||
}
|
||||
|
||||
namespace gdpm::config{
|
||||
struct context{
|
||||
string username;
|
||||
string password;
|
||||
string path;
|
||||
string token;
|
||||
string godot_version;
|
||||
string packages_dir;
|
||||
string tmp_dir;
|
||||
string_map remote_sources;
|
||||
size_t threads;
|
||||
size_t timeout;
|
||||
bool enable_sync;
|
||||
size_t jobs = 1;
|
||||
size_t timeout = 3000;
|
||||
bool enable_sync = true;
|
||||
bool enable_cache = true;
|
||||
bool skip_prompt = false;
|
||||
bool enable_file_logging;
|
||||
bool clean_temporary;
|
||||
int verbose;
|
||||
package::info info;
|
||||
rest_api::request_params api_params;
|
||||
};
|
||||
string to_json(const context& params);
|
||||
error load(std::filesystem::path path, context& config, int verbose = 0);
|
||||
error save(std::filesystem::path path, const context& config, int verbose = 0);
|
||||
|
||||
string to_json(const context& config, bool pretty_print = false);
|
||||
error load(std::filesystem::path path, context& config);
|
||||
error save(std::filesystem::path path, const context& config);
|
||||
error handle_config(config::context& config, const args_t& args, const var_opts& opts);
|
||||
context make_context(const string& username = GDPM_CONFIG_USERNAME, const string& password = GDPM_CONFIG_PASSWORD, const string& path = GDPM_CONFIG_PATH, const string& token = GDPM_CONFIG_TOKEN, const string& godot_version = GDPM_CONFIG_GODOT_VERSION, const string& packages_dir = GDPM_CONFIG_LOCAL_PACKAGES_DIR, const string& tmp_dir = GDPM_CONFIG_LOCAL_TMP_DIR, const string_map& remote_sources = {GDPM_CONFIG_REMOTE_SOURCES}, size_t threads = GDPM_CONFIG_THREADS, size_t timeout = 0, bool enable_sync = GDPM_CONFIG_ENABLE_SYNC, bool enable_file_logging = GDPM_CONFIG_ENABLE_FILE_LOGGING, int verbose = GDPM_CONFIG_VERBOSE);
|
||||
error validate(const rapidjson::Document& doc);
|
||||
void print(const context& config);
|
||||
|
||||
extern context config;
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ namespace gdpm::constants{
|
|||
const std::string LockfilePath(HomePath + ".config/gdpm/gdpm.lck");
|
||||
const std::string LocalPackagesDir(HomePath + ".config/gdpm/packages");
|
||||
const std::string TemporaryPath(HomePath + ".config/gdpm/tmp");
|
||||
const std::string UserAgent("libcurl-agent/1.0");
|
||||
const std::string UserAgent("libcurl-agent/1.0 via GDPM (https://github.com/davidallendj/gdpm)");
|
||||
const std::string AssetRepo("https://godotengine.org/asset-library/api/asset");
|
||||
const std::string HostUrl("https://godotengine.org/asset-library/api");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
#include "package.hpp"
|
||||
#include "types.hpp"
|
||||
#include "result.hpp"
|
||||
#include "config.hpp"
|
||||
#include "rest_api.hpp"
|
||||
#include <cstdio>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
|
@ -13,6 +13,10 @@
|
|||
#include <rapidjson/document.h>
|
||||
|
||||
|
||||
namespace gdpm::config{
|
||||
struct context;
|
||||
}
|
||||
|
||||
namespace gdpm::package {
|
||||
|
||||
struct info {
|
||||
|
|
@ -42,13 +46,14 @@ namespace gdpm::package {
|
|||
GLOBAL_ONLY = 2,
|
||||
LOCAL_ONLY = 3
|
||||
};
|
||||
|
||||
struct params {
|
||||
int parallel_jobs = 1;
|
||||
bool enable_cache = true;
|
||||
bool enable_sync = true;
|
||||
bool skip_prompt = false;
|
||||
string remote_source = "origin";
|
||||
install_method_e install_method = GLOBAL_LINK_LOCAL;
|
||||
args_t sub_commands;
|
||||
var_opts opts;
|
||||
string_list paths;
|
||||
string_list input_files;
|
||||
string remote_source = "origin";
|
||||
install_method_e install_method = GLOBAL_LINK_LOCAL;
|
||||
};
|
||||
|
||||
using info_list = std::vector<info>;
|
||||
|
|
@ -101,10 +106,10 @@ namespace gdpm::package {
|
|||
GDPM_DLL_EXPORT error remove_all(const config::context& config, const params& params = package::params());
|
||||
GDPM_DLL_EXPORT error update(const config::context& config, const title_list& package_titles, const params& params = package::params());
|
||||
GDPM_DLL_EXPORT error search(const config::context& config, const title_list& package_titles, const params& params = package::params());
|
||||
GDPM_DLL_EXPORT error list(const config::context& config, const args_t& args, const opts_t& opts);
|
||||
GDPM_DLL_EXPORT error list(const config::context& config, const params& params = package::params());
|
||||
GDPM_DLL_EXPORT error export_to(const path_list& paths);
|
||||
GDPM_DLL_EXPORT error link(const config::context& config, const title_list& package_titles, const opts_t& opts);
|
||||
GDPM_DLL_EXPORT error clone(const config::context& config, const title_list& package_titles, const opts_t& opts);
|
||||
GDPM_DLL_EXPORT error link(const config::context& config, const title_list& package_titles, const params& params = package::params());
|
||||
GDPM_DLL_EXPORT error clone(const config::context& config, const title_list& package_titles, const params& params = package::params());
|
||||
|
||||
|
||||
GDPM_DLL_EXPORT void print_list(const rapidjson::Document& json);
|
||||
|
|
@ -117,4 +122,6 @@ namespace gdpm::package {
|
|||
/* Dependency Management API */
|
||||
GDPM_DLL_EXPORT result_t<info_list> synchronize_database(const config::context& config, const title_list& package_titles);
|
||||
GDPM_DLL_EXPORT result_t<info_list> resolve_dependencies(const config::context& config, const title_list& package_titles);
|
||||
|
||||
GDPM_DLL_EXPORT string to_json(const info& info, bool pretty_print = false);
|
||||
}
|
||||
|
|
@ -21,16 +21,6 @@ namespace gdpm::package_manager {
|
|||
extern CURLcode res;
|
||||
extern config::context config;
|
||||
|
||||
struct cxxargs{
|
||||
cxxopts::ParseResult result;
|
||||
cxxopts::Options options;
|
||||
};
|
||||
|
||||
struct exec_args{
|
||||
var_args args;
|
||||
var_opts opts;
|
||||
};
|
||||
|
||||
enum class action_e{
|
||||
install,
|
||||
add,
|
||||
|
|
@ -42,18 +32,17 @@ namespace gdpm::package_manager {
|
|||
link,
|
||||
clone,
|
||||
clean,
|
||||
config,
|
||||
fetch,
|
||||
sync,
|
||||
remote,
|
||||
ui,
|
||||
help,
|
||||
none
|
||||
};
|
||||
|
||||
GDPM_DLL_EXPORT result_t<exec_args> initialize(int argc, char **argv);
|
||||
GDPM_DLL_EXPORT int execute(const exec_args& in);
|
||||
GDPM_DLL_EXPORT void finalize();
|
||||
|
||||
/* Auxiliary Functions */
|
||||
GDPM_DLL_EXPORT cxxargs _parse_arguments(int argc, char **argv);
|
||||
GDPM_DLL_EXPORT result_t<exec_args> _handle_arguments(const cxxargs& args);
|
||||
GDPM_DLL_EXPORT error initialize(int argc, char **argv);
|
||||
GDPM_DLL_EXPORT error parse_arguments(int argc, char **argv);
|
||||
GDPM_DLL_EXPORT error finalize();
|
||||
GDPM_DLL_EXPORT void run_command(action_e command, const var_args& args, const var_opts& opts);
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ namespace gdpm::remote{
|
|||
using repo_urls = string_list;
|
||||
using repository_map = string_map;
|
||||
|
||||
GDPM_DLL_EXPORT error _handle_remote(config::context& config, const args_t& args, const opts_t& opts);
|
||||
GDPM_DLL_EXPORT error handle_remote(config::context& config, const args_t& args, const var_opts& opts);
|
||||
GDPM_DLL_EXPORT void set_repositories(config::context& context, const repository_map& repos);
|
||||
GDPM_DLL_EXPORT void add_repositories(config::context& context, const repository_map& repos);
|
||||
GDPM_DLL_EXPORT void remove_respositories(config::context& context, const repo_names& names);
|
||||
|
|
|
|||
|
|
@ -1,11 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
#include "constants.hpp"
|
||||
#include "config.hpp"
|
||||
#include "types.hpp"
|
||||
#include <rapidjson/document.h>
|
||||
#include <rapidjson/writer.h>
|
||||
#include <rapidjson/stringbuffer.h>
|
||||
#include <rapidjson/prettywriter.h>
|
||||
|
||||
|
||||
namespace gdpm::config{
|
||||
struct context;
|
||||
}
|
||||
|
||||
namespace gdpm::rest_api{
|
||||
// See GitHub reference: https://github.com/godotengine/godot-asset-library/blob/master/API.md
|
||||
namespace endpoints{
|
||||
|
|
@ -30,33 +36,34 @@ namespace gdpm::rest_api{
|
|||
bool logout();
|
||||
// bool change_password()
|
||||
|
||||
enum type_e { any, addon, project };
|
||||
enum support_e { all, official, community, testing };
|
||||
enum sort_e { none, rating, cost, name, updated };
|
||||
enum type_e: int { any = 0, addon, project };
|
||||
enum support_e: int { all = 0, official, community, testing };
|
||||
enum sort_e: int { none = 0, rating, cost, name, updated };
|
||||
|
||||
struct context{
|
||||
type_e type;
|
||||
int category;
|
||||
support_e support;
|
||||
string filter;
|
||||
string user;
|
||||
string godot_version;
|
||||
int max_results;
|
||||
int page;
|
||||
sort_e sort;
|
||||
bool reverse;
|
||||
int verbose;
|
||||
struct request_params{
|
||||
int type ;
|
||||
int category;
|
||||
int support;
|
||||
string filter;
|
||||
string user;
|
||||
string godot_version;
|
||||
int max_results;
|
||||
int page;
|
||||
int sort;
|
||||
bool reverse;
|
||||
int verbose;
|
||||
};
|
||||
|
||||
context make_from_config(const config::context& config);
|
||||
context make_context(type_e type = GDPM_DEFAULT_ASSET_TYPE, int category = GDPM_DEFAULT_ASSET_CATEGORY, support_e support = GDPM_DEFAULT_ASSET_SUPPORT, const std::string& filter = GDPM_DEFAULT_ASSET_FILTER, const std::string& user = GDPM_DEFAULT_ASSET_USER, const std::string& godot_version = GDPM_DEFAULT_ASSET_GODOT_VERSION, int max_results = GDPM_DEFAULT_ASSET_MAX_RESULTS, int page = GDPM_DEFAULT_ASSET_PAGE, sort_e sort = GDPM_DEFAULT_ASSET_SORT, bool reverse = GDPM_DEFAULT_ASSET_REVERSE, int verbose = GDPM_DEFAULT_ASSET_VERBOSE);
|
||||
request_params make_from_config(const config::context& config);
|
||||
request_params make_request_params(type_e type = GDPM_DEFAULT_ASSET_TYPE, int category = GDPM_DEFAULT_ASSET_CATEGORY, support_e support = GDPM_DEFAULT_ASSET_SUPPORT, const std::string& filter = GDPM_DEFAULT_ASSET_FILTER, const std::string& user = GDPM_DEFAULT_ASSET_USER, const std::string& godot_version = GDPM_DEFAULT_ASSET_GODOT_VERSION, int max_results = GDPM_DEFAULT_ASSET_MAX_RESULTS, int page = GDPM_DEFAULT_ASSET_PAGE, sort_e sort = GDPM_DEFAULT_ASSET_SORT, bool reverse = GDPM_DEFAULT_ASSET_REVERSE, int verbose = GDPM_DEFAULT_ASSET_VERBOSE);
|
||||
|
||||
string to_json(const rapidjson::Document& doc);
|
||||
string to_string(type_e type);
|
||||
string to_string(support_e support);
|
||||
string to_string(sort_e sort);
|
||||
void _print_params(const context& params);
|
||||
void _print_params(const request_params& params);
|
||||
rapidjson::Document _parse_json(const string& r, int verbose = 0);
|
||||
string _prepare_request(const string& url, const context& context);
|
||||
string _prepare_request(const string& url, const request_params& context);
|
||||
|
||||
bool register_account(const string& username, const string& password, const string& email);
|
||||
bool login(const string& username, const string& password);
|
||||
|
|
@ -64,8 +71,8 @@ namespace gdpm::rest_api{
|
|||
|
||||
rapidjson::Document configure(const string& url = constants::HostUrl, type_e type = any, int verbose = 0);
|
||||
rapidjson::Document get_assets_list(const string& url = constants::HostUrl, type_e type = GDPM_DEFAULT_ASSET_TYPE, int category = GDPM_DEFAULT_ASSET_CATEGORY, support_e support = GDPM_DEFAULT_ASSET_SUPPORT, const string& filter = GDPM_DEFAULT_ASSET_FILTER, const std::string& user = GDPM_DEFAULT_ASSET_USER, const std::string& godot_version = GDPM_DEFAULT_ASSET_GODOT_VERSION, int max_results = GDPM_DEFAULT_ASSET_MAX_RESULTS, int page = GDPM_DEFAULT_ASSET_PAGE, sort_e sort = GDPM_DEFAULT_ASSET_SORT, bool reverse = GDPM_DEFAULT_ASSET_REVERSE, int verbose = GDPM_DEFAULT_ASSET_VERBOSE);
|
||||
rapidjson::Document get_assets_list(const string& url, const context& params = {});
|
||||
rapidjson::Document get_asset(const string& url, int asset_id, const context& params = {});
|
||||
rapidjson::Document get_assets_list(const string& url, const request_params& params = {});
|
||||
rapidjson::Document get_asset(const string& url, int asset_id, const request_params& params = {});
|
||||
bool delete_asset(int asset_id); // ...for moderators
|
||||
bool undelete_asset(int asset_id); // ...for moderators
|
||||
bool set_support_level(int asset_id); // ...for moderators
|
||||
|
|
|
|||
|
|
@ -87,6 +87,7 @@ namespace gdpm{
|
|||
return o;
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
constexpr void get(const var& v, T& target){
|
||||
switch(v.index()){
|
||||
|
|
|
|||
|
|
@ -9,13 +9,15 @@
|
|||
#include <string>
|
||||
#include <fstream>
|
||||
#include <chrono>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include <set>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <fmt/chrono.h>
|
||||
|
||||
namespace gdpm::utils{
|
||||
namespace gdpm::utils {
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
|
|
@ -103,5 +105,11 @@ namespace gdpm::utils{
|
|||
bool prompt_user_yn(const char *message);
|
||||
void delay(std::chrono::milliseconds milliseconds = GDPM_REQUEST_DELAY);
|
||||
std::string join(const std::vector<std::string>& target, const std::string& delimiter = ", ");
|
||||
|
||||
// TODO: Add function to get size of decompressed zip
|
||||
|
||||
namespace json {
|
||||
std::string from_array(const std::set<std::string>& a, const std::string& prefix);
|
||||
std::string from_object(const std::unordered_map<std::string, std::string>& m, const std::string& prefix, const std::string& spaces);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue