Fixed search command not working properly

This commit is contained in:
David Allen 2023-07-02 17:28:18 -06:00
parent 8a7ada342a
commit fb7efdd7a4
10 changed files with 143 additions and 120 deletions

View file

@ -406,6 +406,8 @@ namespace gdpm::package{
return error();
}
error search(
const config::context& config,
@ -420,18 +422,19 @@ namespace gdpm::package{
return error();
}
/* Do a generic query with no filter */
rest_api::request_params rest_api_params = rest_api::make_from_config(config);
if(package_titles.empty()){
return print_asset(rest_api_params);
}
/* Query each package title supplied as input */
for(const auto& p_title : package_titles){
using namespace rapidjson;
string request_url{constants::HostUrl + rest_api::endpoints::GET_Asset};
Document doc = rest_api::get_assets_list(request_url, rest_api_params, p_title);
if(doc.IsNull()){
return log::error_rc(error(
constants::error::HOST_UNREACHABLE,
"Could not fetch metadata. Aborting."
));
error error = print_asset(rest_api_params, p_title, config.style);
if(error.has_occurred()){
log::error(error);
continue;
}
print_list(doc);
}
return error();
}
@ -449,9 +452,9 @@ namespace gdpm::package{
result_t r_installed = cache::get_installed_packages();
info_list p_installed = r_installed.unwrap_unsafe();
if(!p_installed.empty()){
if(config.style == config::print_style::list)
if(config.style == print::style::list)
print_list(p_installed);
else if(config.style == config::print_style::table){
else if(config.style == print::style::table){
print_table(p_installed);
}
}
@ -705,6 +708,35 @@ namespace gdpm::package{
}
void print_table(const rapidjson::Document& json){
using namespace tabulate;
Table table;
table.add_row({
"Asset Name",
"Author",
"Category",
"Version",
"Godot Version",
"License/Cost",
"Last Modified",
"Support"
});
for(const auto& o : json["result"].GetArray()){
table.add_row({
o["title"] .GetString(),
o["author"] .GetString(),
o["category"] .GetString(),
o["version_string"] .GetString(),
o["godot_version"] .GetString(),
o["cost"] .GetString(),
o["modify_date"] .GetString(),
o["support_level"] .GetString()
});
}
table.print(std::cout);
}
result_t<info_list> get_package_info(const title_list& package_titles){
return cache::get_package_info_by_title(package_titles);
}