Update API, README, added functions, and cleaned up implementations

- Changed the remote API
- Added `export` and changed `remote` commands
- Update README.md file
- Removed dependence on `zig c++` in `bin/build.sh` script
- Added error codes to use in place of ints
- Other minor changes
This commit is contained in:
David Allen 2023-05-12 22:27:45 -06:00
parent 88fd230ba6
commit 8e82a22ebd
8 changed files with 273 additions and 192 deletions

View file

@ -1,13 +1,28 @@
#include <string>
#include "log.hpp"
namespace gdpm::error_codes{
enum {
UNKNOWN = 0,
NOT_FOUND = 1,
};
inline std::string to_string(int error_code) {
return "";
}
};
namespace gdpm{
class error{
public:
error(int code = 0, const std::string& message = ""):
error(int code = 0, const std::string& message = "", bool print_message = false):
m_code(code), m_message(message)
{}
{
if(print_message)
print();
}
void set_code(int code) { m_code = code; }
void set_message(const std::string& message) { m_message = message; }
@ -15,9 +30,10 @@ namespace gdpm{
int get_code() const { return m_code; }
std::string get_message() const { return m_message; }
bool has_error() const { return m_code != 0; }
void print(){ log::println(GDPM_COLOR_LOG_ERROR "ERROR: {}" GDPM_COLOR_LOG_RESET, m_message); }
private:
int m_code;
std::string m_message;
};
}
}

View file

@ -1,6 +1,7 @@
#pragma once
#include "config.hpp"
#include "package_manager.hpp"
#include <cstdio>
#include <cxxopts.hpp>
#include <memory>
@ -47,13 +48,13 @@ namespace gdpm::package_manager{
remove,
update,
search,
p_export, /* reserved keyword */
list,
link,
clone,
clean,
sync,
add_remote,
delete_remote,
remote,
help,
none
};
@ -61,25 +62,35 @@ namespace gdpm::package_manager{
GDPM_DLL_EXPORT int initialize(int argc, char **argv);
GDPM_DLL_EXPORT int execute();
GDPM_DLL_EXPORT void finalize();
/* Package management API */
GDPM_DLL_EXPORT error install_packages(const std::vector<std::string>& package_titles, bool skip_prompt = false);
GDPM_DLL_EXPORT error remove_packages(const std::vector<std::string>& package_titles, bool skip_prompt = false);
GDPM_DLL_EXPORT error remove_all_packages();
GDPM_DLL_EXPORT error update_packages(const std::vector<std::string>& package_titles, bool skip_prompt = false);
GDPM_DLL_EXPORT error search_for_packages(const std::vector<std::string>& package_titles, bool skip_prompt = false);
GDPM_DLL_EXPORT void list_information(const std::vector<std::string>& opts);
GDPM_DLL_EXPORT error export_packages(const std::string& path);
GDPM_DLL_EXPORT std::vector<std::string> list_information(const std::vector<std::string>& opts, bool print_list = true);
GDPM_DLL_EXPORT void clean_temporary(const std::vector<std::string>& package_titles);
GDPM_DLL_EXPORT void link_packages(const std::vector<std::string>& package_titles, const std::vector<std::string>& paths);
GDPM_DLL_EXPORT void clone_packages(const std::vector<std::string>& package_titles, const std::vector<std::string>& paths);
GDPM_DLL_EXPORT void add_remote_repository(const std::string& repository, ssize_t offset = -1);
GDPM_DLL_EXPORT void delete_remote_repository(const std::string& repository);
GDPM_DLL_EXPORT void delete_remote_repository(ssize_t index);
/* Remote API */
GDPM_DLL_EXPORT void _handle_remote(const std::string& repository);
GDPM_DLL_EXPORT void remote_add_repository(const std::string& repository, ssize_t offset = -1);
GDPM_DLL_EXPORT void remote_remove_respository(const std::string& repository);
GDPM_DLL_EXPORT void remote_remove_respository(ssize_t index);
GDPM_DLL_EXPORT cxxargs parse_arguments(int argc, char **argv);
GDPM_DLL_EXPORT void handle_arguments(const cxxargs& args);
/* Auxiliary Functions */
GDPM_DLL_EXPORT cxxargs _parse_arguments(int argc, char **argv);
GDPM_DLL_EXPORT void _handle_arguments(const cxxargs& args);
GDPM_DLL_EXPORT void run_command(command_e command, const std::vector<std::string>& package_titles, const std::vector<std::string>& opts);
GDPM_DLL_EXPORT void print_package_list(const rapidjson::Document& json);
GDPM_DLL_EXPORT void print_package_list(const std::vector<package_info>& packages);
GDPM_DLL_EXPORT void print_remote_sources();
GDPM_DLL_EXPORT std::vector<std::string> get_package_titles(const std::vector<package_info>& packages);
/* Dependency Management API */
GDPM_DLL_EXPORT std::vector<package_info> synchronize_database(const std::vector<std::string>& package_titles);
GDPM_DLL_EXPORT std::vector<std::string> resolve_dependencies(const std::vector<std::string>& package_titles);
}