Skip to content

Commit

Permalink
Add history undo command
Browse files Browse the repository at this point in the history
  • Loading branch information
kontura committed Apr 26, 2024
1 parent ed8c56c commit 953bd68
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dnf5/commands/history/history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void HistoryCommand::register_subcommands() {
auto * software_management_commands_group = parser.add_new_group("history_software_management_commands");
software_management_commands_group->set_header("Software Management Commands:");
cmd.register_group(software_management_commands_group);
// register_subcommand(std::make_unique<HistoryUndoCommand>(get_context()), software_management_commands_group);
register_subcommand(std::make_unique<HistoryUndoCommand>(get_context()), software_management_commands_group);
// register_subcommand(std::make_unique<HistoryRedoCommand>(get_context()), software_management_commands_group);
// register_subcommand(std::make_unique<HistoryRollbackCommand>(get_context()), software_management_commands_group);
register_subcommand(std::make_unique<HistoryStoreCommand>(get_context()), software_management_commands_group);
Expand Down
25 changes: 24 additions & 1 deletion dnf5/commands/history/history_undo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,37 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

#include "history_undo.hpp"

#include "commands/history/transaction_id.hpp"
#include "dnf5/shared_options.hpp"

#include <libdnf5/utils/bgettext/bgettext-mark-domain.h>

namespace dnf5 {

using namespace libdnf5::cli;

void HistoryUndoCommand::set_argument_parser() {
get_argument_parser_command()->set_description("Revert all actions from the specified transactions");
transaction_specs = std::make_unique<TransactionSpecArguments>(*this, 1);
auto skip_unavailable = std::make_unique<SkipUnavailableOption>(*this);
}

void HistoryUndoCommand::configure() {
auto & context = get_context();
context.set_load_system_repo(true);
context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED);
}

void HistoryUndoCommand::run() {}
void HistoryUndoCommand::run() {
const auto ts_specs = transaction_specs->get_value();
libdnf5::transaction::TransactionHistory history(get_context().get_base());
std::vector<libdnf5::transaction::Transaction> transactions;
transactions = list_transactions_from_specs(history, ts_specs);

auto goal = get_context().get_goal();
for (const auto & t : transactions) {
goal->add_revert_transaction(t);
}
}

} // namespace dnf5
5 changes: 5 additions & 0 deletions dnf5/commands/history/history_undo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#ifndef DNF5_COMMANDS_HISTORY_HISTORY_UNDO_HPP
#define DNF5_COMMANDS_HISTORY_HISTORY_UNDO_HPP

#include "commands/history/arguments.hpp"

#include <dnf5/context.hpp>


Expand All @@ -31,7 +33,10 @@ class HistoryUndoCommand : public Command {
public:
explicit HistoryUndoCommand(Context & context) : Command(context, "undo") {}
void set_argument_parser() override;
void configure() override;
void run() override;

std::unique_ptr<TransactionSpecArguments> transaction_specs{nullptr};
};


Expand Down

0 comments on commit 953bd68

Please sign in to comment.