Skip to content

Commit

Permalink
history info: add groups and environments to ouput
Browse files Browse the repository at this point in the history
  • Loading branch information
kontura committed Jul 25, 2023
1 parent ac6739c commit 25d9804
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 36 deletions.
27 changes: 27 additions & 0 deletions include/libdnf5-cli/output/transactioninfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#define LIBDNF5_CLI_OUTPUT_TRANSACTIONINFO_HPP

#include "libdnf5-cli/output/key_value_table.hpp"
#include "libdnf5-cli/tty.hpp"

#include <libdnf5/transaction/transaction.hpp>

Expand All @@ -30,6 +31,32 @@ namespace libdnf5::cli::output {

void print_transaction_info(libdnf5::transaction::Transaction & transaction);

template <class Item>
void print_transaction_item_table(std::vector<Item> items, const char * title) {
std::unique_ptr<libscols_table, decltype(&scols_unref_table)> item_list(scols_new_table(), &scols_unref_table);
if (libdnf5::cli::tty::is_interactive()) {
scols_table_enable_colors(item_list.get(), 1);
}
scols_cell_set_data(scols_table_get_title(item_list.get()), title);

// The two spaces indent the table the same way as child lines in KeyValueTable
scols_table_new_column(item_list.get(), " Action", 0, 0);
scols_table_new_column(item_list.get(), "Package", 0, 0);
scols_table_new_column(item_list.get(), "Reason", 0, 0);
scols_table_new_column(item_list.get(), "Repository", 0, 0);

for (auto & pkg : items) {
struct libscols_line * ln = scols_table_new_line(item_list.get(), NULL);
scols_line_set_data(
ln, 0, (" " + libdnf5::transaction::transaction_item_action_to_string(pkg.get_action())).c_str());
scols_line_set_data(ln, 1, pkg.to_string().c_str());
scols_line_set_data(ln, 2, libdnf5::transaction::transaction_item_reason_to_string(pkg.get_reason()).c_str());
scols_line_set_data(ln, 3, pkg.get_repoid().c_str());
}

scols_print_table(item_list.get());
}

} // namespace libdnf5::cli::output

#endif // LIBDNF5_CLI_OUTPUT_TRANSACTIONINFO_HPP
12 changes: 6 additions & 6 deletions include/libdnf5/transaction/comps_environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ class CompsEnvironmentGroupDbUtils;
///
// @replaces libdnf:transaction/CompsEnvironmentItem.hpp:class:CompsEnvironmentItem
class CompsEnvironment : public TransactionItem {
public:
/// Get string representation of the object, which equals to environment_id
///
// @replaces libdnf:transaction/CompsEnvironmentItem.hpp:method:CompsEnvironmentItem.toStr()
std::string to_string() const { return get_environment_id(); }

private:
friend Transaction;
friend CompsEnvironmentDbUtils;
Expand Down Expand Up @@ -102,12 +108,6 @@ class CompsEnvironment : public TransactionItem {
// libdnf5::utils::SQLite3Ptr conn,
// const std::string &pattern);


/// Get string representation of the object, which equals to environment_id
///
// @replaces libdnf:transaction/CompsEnvironmentItem.hpp:method:CompsEnvironmentItem.toStr()
std::string to_string() const { return get_environment_id(); }

std::string environment_id;
std::string name;
std::string translated_name;
Expand Down
11 changes: 6 additions & 5 deletions include/libdnf5/transaction/comps_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ class CompsGroupPackageDbUtils;
///
// @replaces libdnf:transaction/CompsGroupItem.hpp:class:CompsGroupItem
class CompsGroup : public TransactionItem {
public:
/// Get string representation of the object, which equals to group_id
///
// @replaces libdnf:transaction/CompsGroupItem.hpp:method:CompsGroupItem.toStr()
std::string to_string() const { return get_group_id(); }

private:
friend Transaction;
friend CompsGroupPackage;
Expand Down Expand Up @@ -103,11 +109,6 @@ class CompsGroup : public TransactionItem {
// libdnf5::utils::SQLite3Ptr conn,
// const std::string &pattern);

/// Get string representation of the object, which equals to group_id
///
// @replaces libdnf:transaction/CompsGroupItem.hpp:method:CompsGroupItem.toStr()
std::string to_string() const { return get_group_id(); }

std::string group_id;
std::string name;
std::string translated_name;
Expand Down
28 changes: 3 additions & 25 deletions libdnf5-cli/output/transactioninfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

#include "fmt/chrono.h"

#include "libdnf5-cli/tty.hpp"


namespace libdnf5::cli::output {

Expand All @@ -44,30 +42,10 @@ void print_transaction_info(libdnf5::transaction::Transaction & transaction) {
info.add_line("Description", transaction.get_description());
info.add_line("Comment", transaction.get_comment());

info.add_line("Packages altered", "");

std::unique_ptr<libscols_table, decltype(&scols_unref_table)> item_list(scols_new_table(), &scols_unref_table);
if (libdnf5::cli::tty::is_interactive()) {
scols_table_enable_colors(item_list.get(), 1);
}

// The two spaces indent the table the same way as child lines in KeyValueTable
scols_table_new_column(item_list.get(), " Action", 0, 0);
scols_table_new_column(item_list.get(), "Package", 0, 0);
scols_table_new_column(item_list.get(), "Reason", 0, 0);
scols_table_new_column(item_list.get(), "Repository", 0, 0);

for (auto & pkg : transaction.get_packages()) {
struct libscols_line * ln = scols_table_new_line(item_list.get(), NULL);
scols_line_set_data(
ln, 0, (" " + libdnf5::transaction::transaction_item_action_to_string(pkg.get_action())).c_str());
scols_line_set_data(ln, 1, pkg.to_string().c_str());
scols_line_set_data(ln, 2, libdnf5::transaction::transaction_item_reason_to_string(pkg.get_reason()).c_str());
scols_line_set_data(ln, 3, pkg.get_repoid().c_str());
}

info.print();
scols_print_table(item_list.get());
print_transaction_item_table(transaction.get_packages(), "Packages altered:");
print_transaction_item_table(transaction.get_comps_groups(), "Groups altered:");
print_transaction_item_table(transaction.get_comps_environments(), "Environments altered:");
}

} // namespace libdnf5::cli::output

0 comments on commit 25d9804

Please sign in to comment.