diff --git a/dnf5-plugins/automatic_plugin/automatic.cpp b/dnf5-plugins/automatic_plugin/automatic.cpp
index 8471dd8cc..b5eb4caec 100644
--- a/dnf5-plugins/automatic_plugin/automatic.cpp
+++ b/dnf5-plugins/automatic_plugin/automatic.cpp
@@ -24,6 +24,7 @@ along with libdnf. If not, see .
#include "transaction_callbacks_simple.hpp"
#include
+#include
#include
#include
#include
@@ -336,19 +337,26 @@ void AutomaticCommand::run() {
// print resolve logs and the transaction table to the output stream
{
output_stream << std::endl << _("Resolved transaction:") << std::endl;
- libdnf5::cli::output::print_resolve_logs(transaction, output_stream);
+ libdnf5::cli::output::TransactionAdapter cli_output_transaction(*context.get_transaction());
+ libdnf5::cli::output::print_resolve_logs(
+ static_cast(cli_output_transaction), output_stream);
if (!transaction.empty()) {
- libdnf5::cli::output::TransactionSummary summary;
- auto tt = libdnf5::cli::output::create_transaction_table(transaction, summary);
- scols_table_enable_colors(*tt, false);
- scols_table_set_termwidth(*tt, 80);
- char * tt_string = nullptr;
- scols_print_table_to_string(*tt, &tt_string);
- output_stream << tt_string << std::endl;
+ char * tt_string;
+ size_t size;
+ auto * fd = open_memstream(&tt_string, &size);
+ {
+ libdnf5::cli::output::TransactionTable table(
+ static_cast(cli_output_transaction));
+ table.set_colors_enabled(false);
+ table.set_term_width(80);
+ table.set_output_stream(fd);
+ table.print_table();
+ table.print_summary();
+ }
+ fclose(fd);
+ output_stream << tt_string;
free(tt_string);
-
- summary.print(output_stream);
}
}
diff --git a/dnf5/commands/advisory/advisory_info.cpp b/dnf5/commands/advisory/advisory_info.cpp
index af68015ec..ad833889f 100644
--- a/dnf5/commands/advisory/advisory_info.cpp
+++ b/dnf5/commands/advisory/advisory_info.cpp
@@ -19,6 +19,7 @@ along with libdnf. If not, see .
#include "advisory_info.hpp"
+#include
#include
#include
@@ -62,7 +63,8 @@ void AdvisoryInfoCommand::process_and_print_queries(
for (auto advisory : advisories) {
libdnf5::cli::output::AdvisoryInfo advisory_info;
- advisory_info.add_advisory(advisory);
+ output::AdvisoryAdapter cli_advisory(advisory);
+ advisory_info.add_advisory(cli_advisory);
advisory_info.print();
std::cout << std::endl;
}
diff --git a/dnf5/commands/advisory/advisory_list.cpp b/dnf5/commands/advisory/advisory_list.cpp
index b41cb4703..82aff84ae 100644
--- a/dnf5/commands/advisory/advisory_list.cpp
+++ b/dnf5/commands/advisory/advisory_list.cpp
@@ -19,6 +19,7 @@ along with libdnf. If not, see .
#include "advisory_list.hpp"
+#include
#include
#include
#include
@@ -63,12 +64,22 @@ void AdvisoryListCommand::process_and_print_queries(
not_installed_pkgs = advisories.get_advisory_packages_sorted(installed_packages, libdnf5::sack::QueryCmp::GT);
}
+ std::vector> cli_installed_pkgs;
+ std::vector> cli_not_installed_pkgs;
if (with_bz->get_value()) {
libdnf5::cli::output::print_advisorylist_references_table(not_installed_pkgs, installed_pkgs, "bugzilla");
} else if (with_cve->get_value()) {
libdnf5::cli::output::print_advisorylist_references_table(not_installed_pkgs, installed_pkgs, "cve");
} else {
- libdnf5::cli::output::print_advisorylist_table(not_installed_pkgs, installed_pkgs);
+ cli_installed_pkgs.reserve(installed_pkgs.size());
+ for (const auto & obj : installed_pkgs) {
+ cli_installed_pkgs.emplace_back(new output::AdvisoryPackageAdapter(obj));
+ }
+ cli_not_installed_pkgs.reserve(not_installed_pkgs.size());
+ for (const auto & obj : not_installed_pkgs) {
+ cli_not_installed_pkgs.emplace_back(new output::AdvisoryPackageAdapter(obj));
+ }
+ libdnf5::cli::output::print_advisorylist_table(cli_not_installed_pkgs, cli_installed_pkgs);
}
}
diff --git a/dnf5/commands/environment/environment_info.cpp b/dnf5/commands/environment/environment_info.cpp
index 7a9e0eeb3..622cb942e 100644
--- a/dnf5/commands/environment/environment_info.cpp
+++ b/dnf5/commands/environment/environment_info.cpp
@@ -19,11 +19,14 @@ along with libdnf. If not, see .
#include "environment_info.hpp"
+#include
#include
#include
#include
#include
+#include
+
namespace dnf5 {
using namespace libdnf5::cli;
@@ -67,7 +70,8 @@ void EnvironmentInfoCommand::run() {
}
for (auto environment : query.list()) {
- libdnf5::cli::output::print_environmentinfo_table(environment);
+ libdnf5::cli::output::EnvironmentAdapter cli_env(environment);
+ libdnf5::cli::output::print_environmentinfo_table(cli_env);
std::cout << '\n';
}
}
diff --git a/dnf5/commands/environment/environment_list.cpp b/dnf5/commands/environment/environment_list.cpp
index e2522da23..5d875bf6b 100644
--- a/dnf5/commands/environment/environment_list.cpp
+++ b/dnf5/commands/environment/environment_list.cpp
@@ -19,6 +19,7 @@ along with libdnf. If not, see .
#include "environment_list.hpp"
+#include
#include
#include
#include
@@ -66,7 +67,11 @@ void EnvironmentListCommand::run() {
query.filter_installed(false);
}
- libdnf5::cli::output::print_environmentlist_table(query.list());
+ std::vector> cli_envs;
+ for (auto & env : query.list()) {
+ cli_envs.emplace_back(new libdnf5::cli::output::EnvironmentAdapter(env));
+ }
+ libdnf5::cli::output::print_environmentlist_table(cli_envs);
}
} // namespace dnf5
diff --git a/dnf5/commands/group/group_info.cpp b/dnf5/commands/group/group_info.cpp
index bb211f6a0..40dce3f0f 100644
--- a/dnf5/commands/group/group_info.cpp
+++ b/dnf5/commands/group/group_info.cpp
@@ -19,15 +19,19 @@ along with libdnf. If not, see .
#include "group_info.hpp"
+#include
#include
+#include
+
namespace dnf5 {
using namespace libdnf5::cli;
void GroupInfoCommand::print(const libdnf5::comps::GroupQuery & query) {
for (auto group : query.list()) {
- libdnf5::cli::output::print_groupinfo_table(group);
+ libdnf5::cli::output::GroupAdapter cli_group(group);
+ libdnf5::cli::output::print_groupinfo_table(cli_group);
std::cout << '\n';
}
}
diff --git a/dnf5/commands/group/group_list.cpp b/dnf5/commands/group/group_list.cpp
index 03ec0d2dd..b28f48582 100644
--- a/dnf5/commands/group/group_list.cpp
+++ b/dnf5/commands/group/group_list.cpp
@@ -19,6 +19,7 @@ along with libdnf. If not, see .
#include "group_list.hpp"
+#include
#include
#include
#include
@@ -90,7 +91,12 @@ void GroupListCommand::run() {
}
void GroupListCommand::print(const libdnf5::comps::GroupQuery & query) {
- libdnf5::cli::output::print_grouplist_table(query.list());
+ std::vector> items;
+ items.reserve(query.list().size());
+ for (auto & obj : query.list()) {
+ items.emplace_back(new libdnf5::cli::output::GroupAdapter(obj));
+ }
+ libdnf5::cli::output::print_grouplist_table(items);
}
} // namespace dnf5
diff --git a/dnf5/commands/module/module_info.cpp b/dnf5/commands/module/module_info.cpp
index 18eedd836..001f50d1b 100644
--- a/dnf5/commands/module/module_info.cpp
+++ b/dnf5/commands/module/module_info.cpp
@@ -19,13 +19,19 @@ along with libdnf. If not, see .
#include "module_info.hpp"
+#include
#include
#include
namespace dnf5 {
void ModuleInfoCommand::print(const libdnf5::module::ModuleQuery & query) {
- libdnf5::cli::output::print_moduleinfo_table(query.list());
+ std::vector> items;
+ items.reserve(query.list().size());
+ for (auto & obj : query.list()) {
+ items.emplace_back(new libdnf5::cli::output::ModuleItemAdapter(obj));
+ }
+ libdnf5::cli::output::print_moduleinfo_table(items);
}
void ModuleInfoCommand::print_hint() {
diff --git a/dnf5/commands/module/module_list.cpp b/dnf5/commands/module/module_list.cpp
index 66318ffde..75972a73f 100644
--- a/dnf5/commands/module/module_list.cpp
+++ b/dnf5/commands/module/module_list.cpp
@@ -19,6 +19,7 @@ along with libdnf. If not, see .
#include "module_list.hpp"
+#include
#include
#include
#include
@@ -87,7 +88,12 @@ void ModuleListCommand::run() {
}
void ModuleListCommand::print(const libdnf5::module::ModuleQuery & query) {
- libdnf5::cli::output::print_modulelist_table(query.list());
+ std::vector> items;
+ items.reserve(query.list().size());
+ for (auto & obj : query.list()) {
+ items.emplace_back(new output::ModuleItemAdapter(obj));
+ }
+ libdnf5::cli::output::print_modulelist_table(items);
}
void ModuleListCommand::print_hint() {
diff --git a/dnf5/commands/provides/provides.cpp b/dnf5/commands/provides/provides.cpp
index 389e1296e..5a055afee 100644
--- a/dnf5/commands/provides/provides.cpp
+++ b/dnf5/commands/provides/provides.cpp
@@ -16,13 +16,13 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with libdnf. If not, see .
*/
-#include "libdnf5-cli/output/provides.hpp"
-
#include "provides.hpp"
#include "libdnf5/common/sack/query_cmp.hpp"
#include "libdnf5/conf/option_string.hpp"
+#include
+#include
#include
#include
@@ -116,7 +116,8 @@ void ProvidesCommand::run() {
auto matched = filter_spec(spec, full_package_query);
for (auto package : matched.first) {
if (matched.second != libdnf5::cli::output::ProvidesMatchedBy::NO_MATCH) {
- libdnf5::cli::output::print_provides_table(package, spec.c_str(), matched.second);
+ libdnf5::cli::output::PackageAdapter cli_package(package);
+ libdnf5::cli::output::print_provides_table(cli_package, spec.c_str(), matched.second);
any_match = true;
} else {
unmatched_specs.insert(spec);
diff --git a/dnf5/commands/repo/repo_info.cpp b/dnf5/commands/repo/repo_info.cpp
index 6f9331f64..b2cd3a347 100644
--- a/dnf5/commands/repo/repo_info.cpp
+++ b/dnf5/commands/repo/repo_info.cpp
@@ -19,6 +19,7 @@ along with libdnf. If not, see .
#include "repo_info.hpp"
+#include
#include
#include
@@ -26,60 +27,68 @@ along with libdnf. If not, see .
namespace dnf5 {
-struct RepoInfoWrapper {
+class RepoInfoWrapper : public libdnf5::cli::output::IRepoInfo {
public:
RepoInfoWrapper(libdnf5::repo::Repo & repo, uint64_t size, uint64_t pkgs, uint64_t available_pkgs)
- : repo(repo),
+ : repo(&repo),
size(size),
pkgs(pkgs),
available_pkgs(available_pkgs) {}
- std::string get_id() const { return repo.get_id(); }
- std::string get_name() const { return repo.get_name(); }
- std::string get_type() const { return repo.type_to_string(repo.get_type()); }
- bool is_enabled() const { return repo.is_enabled(); }
- int get_priority() const { return repo.get_config().get_priority_option().get_value(); }
- int get_cost() const { return repo.get_config().get_cost_option().get_value(); }
- std::vector get_baseurl() const { return repo.get_config().get_baseurl_option().get_value(); }
- std::string get_metalink() const {
- auto & option = repo.get_config().get_metalink_option();
+ std::string get_id() const override { return repo->get_id(); }
+ std::string get_name() const override { return repo->get_name(); }
+ std::string get_type() const override { return libdnf5::repo::Repo::type_to_string(repo->get_type()); }
+ bool is_enabled() const override { return repo->is_enabled(); }
+ int get_priority() const override { return repo->get_config().get_priority_option().get_value(); }
+ int get_cost() const override { return repo->get_config().get_cost_option().get_value(); }
+ std::vector get_baseurl() const override {
+ return repo->get_config().get_baseurl_option().get_value();
+ }
+ std::string get_metalink() const override {
+ auto & option = repo->get_config().get_metalink_option();
if (option.empty()) {
return "";
} else {
return option.get_value();
}
}
- std::string get_mirrorlist() const {
- auto & option = repo.get_config().get_mirrorlist_option();
+ std::string get_mirrorlist() const override {
+ auto & option = repo->get_config().get_mirrorlist_option();
if (option.empty()) {
return "";
} else {
return option.get_value();
}
}
- int get_metadata_expire() const { return repo.get_config().get_metadata_expire_option().get_value(); }
- std::vector get_excludepkgs() const { return repo.get_config().get_excludepkgs_option().get_value(); }
- std::vector get_includepkgs() const {
- return repo.get_config().get_includepkgs_option().get_value();
+ int get_metadata_expire() const override { return repo->get_config().get_metadata_expire_option().get_value(); }
+ std::vector get_excludepkgs() const override {
+ return repo->get_config().get_excludepkgs_option().get_value();
+ }
+ std::vector get_includepkgs() const override {
+ return repo->get_config().get_includepkgs_option().get_value();
;
}
- bool get_skip_if_unavailable() const { return repo.get_config().get_skip_if_unavailable_option().get_value(); }
- std::vector get_gpgkey() const { return repo.get_config().get_gpgkey_option().get_value(); }
- bool get_gpgcheck() const { return repo.get_config().get_gpgcheck_option().get_value(); }
- bool get_repo_gpgcheck() const { return repo.get_config().get_repo_gpgcheck_option().get_value(); }
- std::string get_repo_file_path() const { return repo.get_repo_file_path(); }
- std::string get_revision() const { return repo.get_revision(); }
- std::vector get_content_tags() const { return repo.get_content_tags(); }
- std::vector> get_distro_tags() const { return repo.get_distro_tags(); }
- int64_t get_timestamp() const { return repo.get_timestamp(); }
- int get_max_timestamp() const { return repo.get_max_timestamp(); }
- uint64_t get_size() const { return size; }
- uint64_t get_pkgs() const { return pkgs; }
- uint64_t get_available_pkgs() const { return available_pkgs; }
- std::vector get_mirrors() const { return repo.get_mirrors(); }
+ bool get_skip_if_unavailable() const override {
+ return repo->get_config().get_skip_if_unavailable_option().get_value();
+ }
+ std::vector get_gpgkey() const override { return repo->get_config().get_gpgkey_option().get_value(); }
+ bool get_gpgcheck() const override { return repo->get_config().get_gpgcheck_option().get_value(); }
+ bool get_repo_gpgcheck() const override { return repo->get_config().get_repo_gpgcheck_option().get_value(); }
+ std::string get_repo_file_path() const override { return repo->get_repo_file_path(); }
+ std::string get_revision() const override { return repo->get_revision(); }
+ std::vector get_content_tags() const override { return repo->get_content_tags(); }
+ std::vector> get_distro_tags() const override {
+ return repo->get_distro_tags();
+ }
+ int64_t get_timestamp() const override { return repo->get_timestamp(); }
+ int get_max_timestamp() const override { return repo->get_max_timestamp(); }
+ uint64_t get_size() const override { return size; }
+ uint64_t get_pkgs() const override { return pkgs; }
+ uint64_t get_available_pkgs() const override { return available_pkgs; }
+ std::vector get_mirrors() const override { return repo->get_mirrors(); }
private:
- libdnf5::repo::Repo & repo;
+ libdnf5::repo::Repo * repo;
uint64_t size;
uint64_t pkgs;
uint64_t available_pkgs;
@@ -110,10 +119,10 @@ void RepoInfoCommand::print(const libdnf5::repo::RepoQuery & query, [[maybe_unus
repo_size += pkg.get_download_size();
}
- libdnf5::cli::output::RepoInfo repo_info;
- auto repo_wrapper = RepoInfoWrapper(*repo, repo_size, pkgs.size(), available_pkgs.size());
- repo_info.add_repo(repo_wrapper);
- repo_info.print();
+ libdnf5::cli::output::RepoInfo repo_info_table;
+ RepoInfoWrapper repo_wrapper(*repo, repo_size, pkgs.size(), available_pkgs.size());
+ repo_info_table.add_repo(repo_wrapper);
+ repo_info_table.print();
std::cout << std::endl;
}
}
diff --git a/dnf5/commands/repo/repo_list.cpp b/dnf5/commands/repo/repo_list.cpp
index 4b9c6dcf4..d41fc5ad7 100644
--- a/dnf5/commands/repo/repo_list.cpp
+++ b/dnf5/commands/repo/repo_list.cpp
@@ -19,6 +19,7 @@ along with libdnf. If not, see .
#include "repo_list.hpp"
+#include
#include
namespace dnf5 {
@@ -74,7 +75,14 @@ void RepoListCommand::run() {
}
void RepoListCommand::print(const libdnf5::repo::RepoQuery & query, bool with_status) {
- libdnf5::cli::output::print_repolist_table(query, with_status, libdnf5::cli::output::COL_REPO_ID);
+ std::vector> cli_repos;
+ auto & repos = query.get_data();
+ cli_repos.reserve(query.size());
+ for (const auto & repo : repos) {
+ cli_repos.emplace_back(new libdnf5::cli::output::RepoAdapter(repo));
+ }
+
+ libdnf5::cli::output::print_repolist_table(cli_repos, with_status, libdnf5::cli::output::COL_REPO_ID);
}
} // namespace dnf5
diff --git a/dnf5/main.cpp b/dnf5/main.cpp
index 1019a1bf3..1699c4461 100644
--- a/dnf5/main.cpp
+++ b/dnf5/main.cpp
@@ -54,8 +54,10 @@ along with libdnf. If not, see .
#include
#include
#include
+#include
#include
#include
+#include
#include
#include
#include
@@ -1115,7 +1117,9 @@ int main(int argc, char * argv[]) try {
download_callbacks->set_number_widget_visible(true);
download_callbacks->set_show_total_bar_limit(0);
- if (!libdnf5::cli::output::print_transaction_table(*context.get_transaction())) {
+ libdnf5::cli::output::TransactionAdapter cli_output_transaction(*context.get_transaction());
+ if (!libdnf5::cli::output::print_transaction_table(
+ static_cast(cli_output_transaction))) {
return static_cast(libdnf5::cli::ExitCode::SUCCESS);
}
diff --git a/dnf5daemon-client/commands/advisory/advisory_info.cpp b/dnf5daemon-client/commands/advisory/advisory_info.cpp
index 805439440..0ce52e279 100644
--- a/dnf5daemon-client/commands/advisory/advisory_info.cpp
+++ b/dnf5daemon-client/commands/advisory/advisory_info.cpp
@@ -21,6 +21,7 @@ along with libdnf. If not, see .
#include "../../wrappers/dbus_advisory_wrapper.hpp"
+#include
#include
#include
@@ -30,7 +31,8 @@ namespace dnfdaemon::client {
void AdvisoryInfoCommand::process_and_print_queries(const std::vector & advisories) {
for (const auto & advisory : advisories) {
libdnf5::cli::output::AdvisoryInfo advisory_info;
- advisory_info.add_advisory(advisory);
+ libdnf5::cli::output::AdvisoryAdapter cli_advisory(advisory);
+ advisory_info.add_advisory(cli_advisory);
advisory_info.print();
std::cout << std::endl;
}
diff --git a/dnf5daemon-client/commands/advisory/advisory_list.cpp b/dnf5daemon-client/commands/advisory/advisory_list.cpp
index c35b5625b..91befe9ae 100644
--- a/dnf5daemon-client/commands/advisory/advisory_list.cpp
+++ b/dnf5daemon-client/commands/advisory/advisory_list.cpp
@@ -21,6 +21,7 @@ along with libdnf. If not, see .
#include "../../wrappers/dbus_advisory_wrapper.hpp"
+#include
#include
#include
@@ -28,8 +29,8 @@ along with libdnf. If not, see .
namespace dnfdaemon::client {
void AdvisoryListCommand::process_and_print_queries(const std::vector & advisories) {
- std::vector installed_pkgs;
- std::vector not_installed_pkgs;
+ std::vector> installed_pkgs;
+ std::vector> not_installed_pkgs;
for (const auto & advisory : advisories) {
// TODO(mblaha): filter the output according contains_pkgs?
@@ -45,9 +46,9 @@ void AdvisoryListCommand::process_and_print_queries(const std::vector.
#include
#include
+#include
#include
#include
#include
@@ -68,7 +69,8 @@ void TransactionCommand::run_transaction() {
ctx.reset_download_cb();
// print the transaction to the user and ask for confirmation
- if (!libdnf5::cli::output::print_transaction_table(dbus_goal_wrapper)) {
+ libdnf5::cli::output::TransactionAdapter cli_output_transaction(dbus_goal_wrapper);
+ if (!libdnf5::cli::output::print_transaction_table(cli_output_transaction)) {
return;
}
diff --git a/dnf5daemon-client/commands/group/group_list.cpp b/dnf5daemon-client/commands/group/group_list.cpp
index 88344c291..fed539531 100644
--- a/dnf5daemon-client/commands/group/group_list.cpp
+++ b/dnf5daemon-client/commands/group/group_list.cpp
@@ -22,6 +22,7 @@ along with libdnf. If not, see .
#include "context.hpp"
#include "wrappers/dbus_group_wrapper.hpp"
+#include
#include
#include
#include
@@ -84,17 +85,20 @@ void GroupListCommand::run() {
.storeResultsTo(raw_groups);
std::vector groups{};
+ std::vector> cli_groups;
for (auto & group : raw_groups) {
groups.push_back(DbusGroupWrapper(group));
+ cli_groups.emplace_back(new libdnf5::cli::output::GroupAdapter(DbusGroupWrapper(group)));
}
if (command == "info") {
for (auto & group : groups) {
- libdnf5::cli::output::print_groupinfo_table(group);
+ libdnf5::cli::output::GroupAdapter cli_group(group);
+ libdnf5::cli::output::print_groupinfo_table(cli_group);
std::cout << '\n';
}
} else {
- libdnf5::cli::output::print_grouplist_table(groups);
+ libdnf5::cli::output::print_grouplist_table(cli_groups);
}
}
diff --git a/dnf5daemon-client/commands/repolist/repolist.cpp b/dnf5daemon-client/commands/repolist/repolist.cpp
index a1b8ef4d8..265ab0a66 100644
--- a/dnf5daemon-client/commands/repolist/repolist.cpp
+++ b/dnf5daemon-client/commands/repolist/repolist.cpp
@@ -88,6 +88,21 @@ void RepolistCommand::set_argument_parser() {
cmd.register_positional_arg(repos);
}
+
+class CliRepoAdapter : public libdnf5::cli::output::IRepo {
+public:
+ CliRepoAdapter(const DbusRepoWrapper * repo) : repo{repo} {}
+
+ std::string get_id() const override { return repo->get_id(); }
+
+ bool is_enabled() const override { return repo->is_enabled(); }
+
+ std::string get_name() const override { return repo->get_name(); }
+
+private:
+ const DbusRepoWrapper * repo;
+};
+
void RepolistCommand::run() {
auto & ctx = get_context();
@@ -146,8 +161,15 @@ void RepolistCommand::run() {
if (command == "repolist") {
// print the output table
bool with_status = enable_disable_option->get_value() == "all";
- libdnf5::cli::output::print_repolist_table(
- DbusQueryRepoWrapper(repositories), with_status, libdnf5::cli::output::COL_REPO_ID);
+
+ std::vector> cli_repos;
+ auto repo_query = DbusQueryRepoWrapper(repositories);
+ cli_repos.reserve(repo_query.get_data().size());
+ for (const auto & repo : repo_query.get_data()) {
+ cli_repos.emplace_back(new CliRepoAdapter(repo.get()));
+ }
+
+ libdnf5::cli::output::print_repolist_table(cli_repos, with_status, libdnf5::cli::output::COL_REPO_ID);
} else {
// repoinfo command
diff --git a/dnf5daemon-client/commands/repoquery/repoquery.cpp b/dnf5daemon-client/commands/repoquery/repoquery.cpp
index 8c8711d59..fbc65c092 100644
--- a/dnf5daemon-client/commands/repoquery/repoquery.cpp
+++ b/dnf5daemon-client/commands/repoquery/repoquery.cpp
@@ -24,6 +24,7 @@ along with libdnf. If not, see .
#include
#include
+#include
#include
#include
#include
@@ -146,10 +147,11 @@ void RepoqueryCommand::run() {
for (auto & raw_package : packages) {
--num_packages;
DbusPackageWrapper package(raw_package);
+ libdnf5::cli::output::PackageAdapter cli_pkg(package);
if (info_option->get_value()) {
auto out = libdnf5::cli::output::PackageInfoSections();
out.setup_cols();
- out.add_package(package);
+ out.add_package(cli_pkg);
out.print();
if (num_packages) {
std::cout << std::endl;
diff --git a/dnf5daemon-client/wrappers/dbus_repo_wrapper.hpp b/dnf5daemon-client/wrappers/dbus_repo_wrapper.hpp
index 04b2966bc..b8dc2a07f 100644
--- a/dnf5daemon-client/wrappers/dbus_repo_wrapper.hpp
+++ b/dnf5daemon-client/wrappers/dbus_repo_wrapper.hpp
@@ -21,12 +21,13 @@ along with libdnf. If not, see .
#define DNF5DAEMON_CLIENT_WRAPPERS_DBUS_REPO_WRAPPER_HPP
#include
+#include
#include
namespace dnfdaemon::client {
-class DbusRepoWrapper {
+class DbusRepoWrapper : public libdnf5::cli::output::IRepoInfo {
public:
explicit DbusRepoWrapper(dnfdaemon::KeyValueMap & rawdata) : rawdata(rawdata){};
diff --git a/dnf5daemon-client/wrappers/dbus_transaction_package_wrapper.hpp b/dnf5daemon-client/wrappers/dbus_transaction_package_wrapper.hpp
index 0111e0727..c63ad88ca 100644
--- a/dnf5daemon-client/wrappers/dbus_transaction_package_wrapper.hpp
+++ b/dnf5daemon-client/wrappers/dbus_transaction_package_wrapper.hpp
@@ -39,6 +39,7 @@ class DbusTransactionPackageWrapper {
transaction_item_attrs(std::get<3>(dti)),
package(std::get<4>(dti)) {}
+ const DbusPackageWrapper & get_package() const noexcept { return package; }
DbusPackageWrapper & get_package() noexcept { return package; }
libdnf5::transaction::TransactionItemAction get_action() const noexcept { return action; }
libdnf5::transaction::TransactionItemReason get_reason() const noexcept { return reason; }
diff --git a/include/libdnf5-cli/output/advisoryinfo.hpp b/include/libdnf5-cli/output/advisoryinfo.hpp
index 9b8621c4d..1c3b787af 100644
--- a/include/libdnf5-cli/output/advisoryinfo.hpp
+++ b/include/libdnf5-cli/output/advisoryinfo.hpp
@@ -21,74 +21,22 @@ along with libdnf. If not, see .
#ifndef LIBDNF5_CLI_OUTPUT_ADVISORYINFO_HPP
#define LIBDNF5_CLI_OUTPUT_ADVISORYINFO_HPP
-#include "utils/string.hpp"
-
-#include "libdnf5-cli/output/key_value_table.hpp"
-
-#include
-
+#include "interfaces/advisory.hpp"
namespace libdnf5::cli::output {
-
-class AdvisoryInfo : public KeyValueTable {
+class AdvisoryInfo {
public:
- template
- void add_advisory(AdvisoryClass & advisory);
-};
+ AdvisoryInfo();
+ ~AdvisoryInfo();
+ void add_advisory(IAdvisory & advisory);
+ void print();
-template
-void AdvisoryInfo::add_advisory(AdvisoryClass & advisory) {
- add_line("Name", advisory.get_name(), "bold");
- add_line("Title", advisory.get_title());
- add_line("Severity", advisory.get_severity());
- add_line("Type", advisory.get_type());
- add_line("Status", advisory.get_status());
- add_line("Vendor", advisory.get_vendor());
- add_line("Issued", libdnf5::utils::string::format_epoch(advisory.get_buildtime()));
- add_lines("Description", libdnf5::utils::string::split(advisory.get_description(), "\n"));
- add_line("Message", advisory.get_message());
- add_line("Rights", advisory.get_rights());
-
- // References
- for (auto reference : advisory.get_references()) {
- auto group_reference = add_line("Reference", "");
- add_line("Title", reference.get_title(), "bold", group_reference);
- add_line("Id", reference.get_id(), nullptr, group_reference);
- add_line("Type", reference.get_type_cstring(), nullptr, group_reference);
- add_line("Url", reference.get_url(), nullptr, group_reference);
- }
-
- // Collections
- for (auto collection : advisory.get_collections()) {
- auto group_collection = add_line("Collection", "");
-
- // Modules
- auto modules = collection.get_modules();
- if (!modules.empty()) {
- auto module_iter = modules.begin();
- add_line("Modules", module_iter->get_nsvca(), nullptr, group_collection);
- module_iter++;
- while (module_iter != modules.end()) {
- add_line("", module_iter->get_nsvca(), nullptr, group_collection);
- module_iter++;
- }
- }
-
- // Packages
- auto packages = collection.get_packages();
- if (!packages.empty()) {
- auto package_iter = packages.begin();
- add_line("Packages", package_iter->get_nevra(), nullptr, group_collection);
- package_iter++;
- while (package_iter != packages.end()) {
- add_line("", package_iter->get_nevra(), nullptr, group_collection);
- package_iter++;
- }
- }
- }
-}
+private:
+ class Impl;
+ std::unique_ptr p_impl;
+};
} // namespace libdnf5::cli::output
diff --git a/include/libdnf5-cli/output/advisorylist.hpp b/include/libdnf5-cli/output/advisorylist.hpp
index b3c44f073..45da2240e 100644
--- a/include/libdnf5-cli/output/advisorylist.hpp
+++ b/include/libdnf5-cli/output/advisorylist.hpp
@@ -21,56 +21,16 @@ along with libdnf. If not, see .
#ifndef LIBDNF5_CLI_OUTPUT_ADVISORYLIST_HPP
#define LIBDNF5_CLI_OUTPUT_ADVISORYLIST_HPP
+#include "interfaces/advisory.hpp"
+
#include
#include
-#include
namespace libdnf5::cli::output {
-struct libscols_table * create_advisorylist_table(std::string column_id_name);
-
-void sort_advisorylist_table(libscols_table * table);
-
-void add_line_into_advisorylist_table(
- struct libscols_table * table,
- const char * name,
- const char * type,
- const char * severity,
- const char * package,
- unsigned long long buildtime,
- bool installed);
-
-template
void print_advisorylist_table(
- std::vector & advisory_package_list_not_installed,
- std::vector & advisory_package_list_installed) {
- struct libscols_table * table = create_advisorylist_table("Name");
- for (auto adv_pkg : advisory_package_list_not_installed) {
- auto advisory = adv_pkg.get_advisory();
- add_line_into_advisorylist_table(
- table,
- advisory.get_name().c_str(),
- advisory.get_type().c_str(),
- advisory.get_severity().c_str(),
- adv_pkg.get_nevra().c_str(),
- advisory.get_buildtime(),
- false);
- }
- for (auto adv_pkg : advisory_package_list_installed) {
- auto advisory = adv_pkg.get_advisory();
- add_line_into_advisorylist_table(
- table,
- advisory.get_name().c_str(),
- advisory.get_type().c_str(),
- advisory.get_severity().c_str(),
- adv_pkg.get_nevra().c_str(),
- advisory.get_buildtime(),
- true);
- }
- sort_advisorylist_table(table);
- scols_print_table(table);
- scols_unref_table(table);
-}
+ std::vector> & advisory_package_list_not_installed,
+ std::vector> & advisory_package_list_installed);
void print_advisorylist_references_table(
std::vector & advisory_package_list_not_installed,
diff --git a/include/libdnf5-cli/output/environmentinfo.hpp b/include/libdnf5-cli/output/environmentinfo.hpp
index 6e995bc0e..60a26953d 100644
--- a/include/libdnf5-cli/output/environmentinfo.hpp
+++ b/include/libdnf5-cli/output/environmentinfo.hpp
@@ -21,98 +21,11 @@ along with libdnf. If not, see .
#ifndef LIBDNF5_CLI_OUTPUT_ENVIRONMENTINFO_HPP
#define LIBDNF5_CLI_OUTPUT_ENVIRONMENTINFO_HPP
-#include "libdnf5-cli/tty.hpp"
-
-// TODO(lukash) include from common in a public libdnf-cli header
-#include "utils/string.hpp"
-
-#include
-
+#include "interfaces/comps.hpp"
namespace libdnf5::cli::output {
-
-static void add_line_into_environmentinfo_table(
- struct libscols_table * table, const char * key, const char * value, const char * color) {
- struct libscols_line * ln = scols_table_new_line(table, NULL);
- scols_line_set_data(ln, 0, key);
- scols_line_set_data(ln, 1, value);
-
- if (color && strcmp(color, "") != 0) {
- auto cell_value = scols_line_get_cell(ln, 1);
- scols_cell_set_color(cell_value, color);
- }
-}
-
-
-static void add_line_into_environmentinfo_table(struct libscols_table * table, const char * key, const char * value) {
- add_line_into_environmentinfo_table(table, key, value, "");
-}
-
-
-static void add_groups(struct libscols_table * table, std::vector groups, const char * group_type_desc) {
- if (groups.empty()) {
- // don't even print the group type description
- return;
- }
-
- struct libscols_line * ln = scols_table_new_line(table, NULL);
- scols_line_set_data(ln, 0, group_type_desc);
-
- auto it = groups.begin();
- // put the first group at the same line as description
- scols_line_set_data(ln, 1, it->c_str());
- it++;
-
- // put the remaining group on separate lines
- for (; it != groups.end(); it++) {
- struct libscols_line * group_ln = scols_table_new_line(table, ln);
- scols_line_set_data(group_ln, 1, it->c_str());
- }
-}
-
-
-template
-static struct libscols_table * create_environmentinfo_table(EnvironmentType & environment) {
- struct libscols_table * table = scols_new_table();
- scols_table_enable_noheadings(table, 1);
- scols_table_set_column_separator(table, " : ");
- scols_table_new_column(table, "key", 20, SCOLS_FL_TREE);
- struct libscols_column * cl = scols_table_new_column(table, "value", 10, SCOLS_FL_WRAP);
- scols_column_set_safechars(cl, "\n");
- scols_column_set_wrapfunc(cl, scols_wrapnl_chunksize, scols_wrapnl_nextchunk, nullptr);
- if (libdnf5::cli::tty::is_interactive()) {
- scols_table_enable_colors(table, true);
- }
- auto sy = scols_new_symbols();
- scols_symbols_set_branch(sy, " ");
- scols_symbols_set_right(sy, " ");
- scols_symbols_set_vertical(sy, "");
- scols_table_set_symbols(table, sy);
- scols_unref_symbols(sy);
-
- add_line_into_environmentinfo_table(table, "Id", environment.get_environmentid().c_str(), "bold");
- add_line_into_environmentinfo_table(table, "Name", environment.get_name().c_str());
- add_line_into_environmentinfo_table(table, "Description", environment.get_description().c_str());
- add_line_into_environmentinfo_table(table, "Order", environment.get_order().c_str());
- add_line_into_environmentinfo_table(table, "Installed", environment.get_installed() ? "True" : "False");
- add_line_into_environmentinfo_table(
- table, "Repositories", libdnf5::utils::string::join(environment.get_repos(), ", ").c_str());
-
- add_groups(table, environment.get_groups(), "Required groups");
- add_groups(table, environment.get_optional_groups(), "Optional groups");
-
- return table;
-}
-
-
-template
-void print_environmentinfo_table(EnvironmentType & environment) {
- struct libscols_table * table = create_environmentinfo_table(environment);
- scols_print_table(table);
- scols_unref_table(table);
-}
-
+void print_environmentinfo_table(IEnvironment & environment);
} // namespace libdnf5::cli::output
diff --git a/include/libdnf5-cli/output/environmentlist.hpp b/include/libdnf5-cli/output/environmentlist.hpp
index 1fbc63b94..0d3f610f4 100644
--- a/include/libdnf5-cli/output/environmentlist.hpp
+++ b/include/libdnf5-cli/output/environmentlist.hpp
@@ -21,59 +21,11 @@ along with libdnf. If not, see .
#ifndef LIBDNF5_CLI_OUTPUT_ENVIRONMENTLIST_HPP
#define LIBDNF5_CLI_OUTPUT_ENVIRONMENTLIST_HPP
-#include "libdnf5-cli/tty.hpp"
-
-#include
+#include "interfaces/comps.hpp"
namespace libdnf5::cli::output {
-
-// environment list table columns
-enum { COL_ENVIRONMENT_ID, COL_ENVIRONMENT_NAME, COL_INSTALLED };
-
-
-static struct libscols_table * create_environmentlist_table() {
- struct libscols_table * table = scols_new_table();
- if (libdnf5::cli::tty::is_interactive()) {
- scols_table_enable_colors(table, 1);
- }
- struct libscols_column * cl = scols_table_new_column(table, "ID", 20, 0);
- scols_column_set_cmpfunc(cl, scols_cmpstr_cells, NULL);
- scols_table_new_column(table, "Name", 0.5, SCOLS_FL_TRUNC);
- scols_table_new_column(table, "Installed", 0.1, SCOLS_FL_RIGHT);
- return table;
-}
-
-
-static void add_line_into_environmentlist_table(
- struct libscols_table * table, const char * id, const char * name, bool installed) {
- struct libscols_line * ln = scols_table_new_line(table, NULL);
- scols_line_set_data(ln, COL_ENVIRONMENT_ID, id);
- scols_line_set_data(ln, COL_ENVIRONMENT_NAME, name);
- scols_line_set_data(ln, COL_INSTALLED, installed ? "yes" : "no");
- if (installed) {
- struct libscols_cell * cl = scols_line_get_cell(ln, COL_INSTALLED);
- scols_cell_set_color(cl, "green");
- }
-}
-
-
-template
-void print_environmentlist_table(Query & environment_list) {
- struct libscols_table * table = create_environmentlist_table();
- for (auto environment : environment_list) {
- add_line_into_environmentlist_table(
- table,
- environment.get_environmentid().c_str(),
- environment.get_name().c_str(),
- environment.get_installed());
- }
- auto cl = scols_table_get_column(table, COL_ENVIRONMENT_ID);
- scols_sort_table(table, cl);
- scols_print_table(table);
- scols_unref_table(table);
-}
-
+void print_environmentlist_table(std::vector> & environment_list);
} // namespace libdnf5::cli::output
diff --git a/include/libdnf5-cli/output/groupinfo.hpp b/include/libdnf5-cli/output/groupinfo.hpp
index 3d50691a7..21369a844 100644
--- a/include/libdnf5-cli/output/groupinfo.hpp
+++ b/include/libdnf5-cli/output/groupinfo.hpp
@@ -21,116 +21,11 @@ along with libdnf. If not, see .
#ifndef LIBDNF5_CLI_OUTPUT_GROUPINFO_HPP
#define LIBDNF5_CLI_OUTPUT_GROUPINFO_HPP
-#include "libdnf5-cli/tty.hpp"
-
-// TODO(lukash) include from common in a public libdnf-cli header
-#include "utils/string.hpp"
-
-#include
-#include
-
+#include "interfaces/comps.hpp"
namespace libdnf5::cli::output {
-
-static void add_line_into_groupinfo_table(
- struct libscols_table * table, const char * key, const char * value, const char * color) {
- struct libscols_line * ln = scols_table_new_line(table, NULL);
- scols_line_set_data(ln, 0, key);
- scols_line_set_data(ln, 1, value);
-
- if (color && strcmp(color, "") != 0) {
- auto cell_value = scols_line_get_cell(ln, 1);
- scols_cell_set_color(cell_value, color);
- }
-}
-
-
-static void add_line_into_groupinfo_table(struct libscols_table * table, const char * key, const char * value) {
- add_line_into_groupinfo_table(table, key, value, "");
-}
-
-
-template
-static void add_packages(
- struct libscols_table * table,
- GroupType & group,
- libdnf5::comps::PackageType pkg_type,
- const char * pkg_type_desc) {
- std::set packages;
-
- // we don't mind iterating through all packages in every add_packages() call,
- // because performance is not an issue here
- for (auto & package : group.get_packages()) {
- if (package.get_type() == pkg_type) {
- packages.emplace(package.get_name());
- }
- }
-
- if (packages.empty()) {
- // don't even print the package type description
- return;
- }
-
- struct libscols_line * ln = scols_table_new_line(table, NULL);
- scols_line_set_data(ln, 0, pkg_type_desc);
-
- auto it = packages.begin();
- // put the first package at the same line as description
- scols_line_set_data(ln, 1, it->c_str());
- it++;
-
- // put the remaining packages on separate lines
- for (; it != packages.end(); it++) {
- struct libscols_line * pkg_ln = scols_table_new_line(table, ln);
- scols_line_set_data(pkg_ln, 1, it->c_str());
- }
-}
-
-
-template
-static struct libscols_table * create_groupinfo_table(GroupType & group) {
- struct libscols_table * table = scols_new_table();
- scols_table_enable_noheadings(table, 1);
- scols_table_set_column_separator(table, " : ");
- scols_table_new_column(table, "key", 20, SCOLS_FL_TREE);
- struct libscols_column * cl = scols_table_new_column(table, "value", 10, SCOLS_FL_WRAP);
- scols_column_set_safechars(cl, "\n");
- scols_column_set_wrapfunc(cl, scols_wrapnl_chunksize, scols_wrapnl_nextchunk, nullptr);
- if (libdnf5::cli::tty::is_interactive()) {
- scols_table_enable_colors(table, true);
- }
- auto sy = scols_new_symbols();
- scols_symbols_set_branch(sy, " ");
- scols_symbols_set_right(sy, " ");
- scols_symbols_set_vertical(sy, "");
- scols_table_set_symbols(table, sy);
- scols_unref_symbols(sy);
-
- add_line_into_groupinfo_table(table, "Id", group.get_groupid().c_str(), "bold");
- add_line_into_groupinfo_table(table, "Name", group.get_name().c_str());
- add_line_into_groupinfo_table(table, "Description", group.get_description().c_str());
- add_line_into_groupinfo_table(table, "Installed", group.get_installed() ? "yes" : "no");
- add_line_into_groupinfo_table(table, "Order", group.get_order().c_str());
- add_line_into_groupinfo_table(table, "Langonly", group.get_langonly().c_str());
- add_line_into_groupinfo_table(table, "Uservisible", group.get_uservisible() ? "yes" : "no");
- add_line_into_groupinfo_table(table, "Repositories", libdnf5::utils::string::join(group.get_repos(), ", ").c_str());
-
- add_packages(table, group, libdnf5::comps::PackageType::MANDATORY, "Mandatory packages");
- add_packages(table, group, libdnf5::comps::PackageType::DEFAULT, "Default packages");
- add_packages(table, group, libdnf5::comps::PackageType::OPTIONAL, "Optional packages");
- add_packages(table, group, libdnf5::comps::PackageType::CONDITIONAL, "Conditional packages");
-
- return table;
-}
-
-template
-void print_groupinfo_table(GroupType & group) {
- struct libscols_table * table = create_groupinfo_table(group);
- scols_print_table(table);
- scols_unref_table(table);
-}
-
+void print_groupinfo_table(IGroup & group);
} // namespace libdnf5::cli::output
diff --git a/include/libdnf5-cli/output/grouplist.hpp b/include/libdnf5-cli/output/grouplist.hpp
index 7e8b66c71..2fb0ed15b 100644
--- a/include/libdnf5-cli/output/grouplist.hpp
+++ b/include/libdnf5-cli/output/grouplist.hpp
@@ -21,56 +21,11 @@ along with libdnf. If not, see .
#ifndef LIBDNF5_CLI_OUTPUT_GROUPLIST_HPP
#define LIBDNF5_CLI_OUTPUT_GROUPLIST_HPP
-#include "libdnf5-cli/tty.hpp"
-
-#include
+#include "interfaces/comps.hpp"
namespace libdnf5::cli::output {
-
-// group list table columns
-enum { COL_GROUP_ID, COL_GROUP_NAME, COL_INSTALLED };
-
-
-static struct libscols_table * create_grouplist_table() {
- struct libscols_table * table = scols_new_table();
- if (libdnf5::cli::tty::is_interactive()) {
- scols_table_enable_colors(table, 1);
- }
- struct libscols_column * cl = scols_table_new_column(table, "ID", 20, 0);
- scols_column_set_cmpfunc(cl, scols_cmpstr_cells, NULL);
- scols_table_new_column(table, "Name", 0.5, SCOLS_FL_TRUNC);
- scols_table_new_column(table, "Installed", 0.1, SCOLS_FL_RIGHT);
- return table;
-}
-
-
-static void add_line_into_grouplist_table(
- struct libscols_table * table, const char * id, const char * name, bool installed) {
- struct libscols_line * ln = scols_table_new_line(table, NULL);
- scols_line_set_data(ln, COL_GROUP_ID, id);
- scols_line_set_data(ln, COL_GROUP_NAME, name);
- scols_line_set_data(ln, COL_INSTALLED, installed ? "yes" : "no");
- if (installed) {
- struct libscols_cell * cl = scols_line_get_cell(ln, COL_INSTALLED);
- scols_cell_set_color(cl, "green");
- }
-}
-
-
-template
-void print_grouplist_table(Query & group_list) {
- struct libscols_table * table = create_grouplist_table();
- for (auto group : group_list) {
- add_line_into_grouplist_table(
- table, group.get_groupid().c_str(), group.get_name().c_str(), group.get_installed());
- }
- auto cl = scols_table_get_column(table, COL_GROUP_ID);
- scols_sort_table(table, cl);
- scols_print_table(table);
- scols_unref_table(table);
-}
-
+void print_grouplist_table(std::vector> & group_list);
} // namespace libdnf5::cli::output
diff --git a/include/libdnf5-cli/output/moduleinfo.hpp b/include/libdnf5-cli/output/moduleinfo.hpp
index 96671f712..f9423caef 100644
--- a/include/libdnf5-cli/output/moduleinfo.hpp
+++ b/include/libdnf5-cli/output/moduleinfo.hpp
@@ -21,100 +21,18 @@ along with libdnf. If not, see .
#ifndef LIBDNF_CLI_OUTPUT_MODULEINFO_HPP
#define LIBDNF_CLI_OUTPUT_MODULEINFO_HPP
-#include "key_value_table.hpp"
-#include "utils/string.hpp"
+#include "interfaces/module.hpp"
-#include "libdnf5-cli/tty.hpp"
-
-#include
-#include
-#include
-#include
-
-#include