Skip to content

Allow unlimited number of arguments for history list and info #1755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dnf5/commands/history/arguments.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace dnf5 {
class TransactionSpecArguments : public libdnf5::cli::session::StringArgumentList {
public:
explicit TransactionSpecArguments(
libdnf5::cli::session::Command & command, int nrepeats = libdnf5::cli::ArgumentParser::PositionalArg::OPTIONAL)
libdnf5::cli::session::Command & command, int nrepeats = libdnf5::cli::ArgumentParser::PositionalArg::UNLIMITED)
: StringArgumentList(command, "transaction-id", _("Transaction ID"), nrepeats) {}
};

Expand Down
27 changes: 14 additions & 13 deletions dnf5/commands/history/history_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ void HistoryStoreCommand::run() {
const auto ts_specs = transaction_specs->get_value();
libdnf5::transaction::TransactionHistory history(get_context().get_base());
std::vector<libdnf5::transaction::Transaction> transactions;

if (ts_specs.empty()) {
transactions = list_transactions_from_specs(history, {"last"});
} else {
transactions = list_transactions_from_specs(history, ts_specs);
}

if (transactions.empty()) {
throw libdnf5::cli::CommandExitError(1, M_("No matching transaction ID found, exactly one required."));
}
if (transactions.size() != 1) {
throw libdnf5::cli::CommandExitError(1, M_("Multiple transactions selected for storing, only one allowed."));
}

auto logger = get_context().get_base().get_logger();

std::filesystem::create_directories(output_option->get_value());
Expand All @@ -70,19 +84,6 @@ void HistoryStoreCommand::run() {
}
}

if (ts_specs.empty()) {
transactions = list_transactions_from_specs(history, {"last"});
} else {
transactions = list_transactions_from_specs(history, ts_specs);
}

if (transactions.empty()) {
throw libdnf5::cli::CommandExitError(1, M_("No matching transaction ID found, exactly one required."));
}
if (transactions.size() != 1) {
throw libdnf5::cli::CommandExitError(1, M_("Multiple transactions selected for storing, only one allowed."));
}

const std::string json = transactions[0].serialize();

auto tmp_file = libdnf5::utils::fs::TempFile(trans_file_path.parent_path(), trans_file_path.filename());
Expand Down
Loading