Skip to content
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

[DNF5] --enable-plugin and --disable-pluin: no match found message #1432

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
20 changes: 18 additions & 2 deletions dnf5/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ class Context::Impl {

void load_repos(bool load_system);

std::vector<std::pair<std::vector<std::string>, bool>> libdnf5_plugins_enablement;

void store_offline(libdnf5::base::Transaction & transaction);

std::filesystem::path transaction_store_path;
Expand Down Expand Up @@ -182,13 +180,23 @@ class Context::Impl {
std::vector<std::pair<std::string, std::string>> & get_repos_from_path() { return repos_from_path; }
const std::vector<std::pair<std::string, std::string>> & get_repos_from_path() const { return repos_from_path; }

std::vector<std::pair<std::vector<std::string>, bool>> & get_libdnf_plugins_enablement() {
return libdnf_plugins_enablement;
}
const std::vector<std::pair<std::vector<std::string>, bool>> & get_libdnf_plugins_enablement() const {
return libdnf_plugins_enablement;
}

private:
Context & owner;

libdnf5::Base base;
std::vector<std::pair<std::string, std::string>> setopts;
std::vector<std::pair<std::string, std::string>> repos_from_path;

/// list of lists of libdnf plugin names (global patterns) that we want to enable (true) or disable (false)
std::vector<std::pair<std::vector<std::string>, bool>> libdnf_plugins_enablement;

std::string cmdline;

/// Points to user comment.
Expand Down Expand Up @@ -618,6 +626,14 @@ const std::vector<std::pair<std::string, std::string>> & Context::get_repos_from
return p_impl->get_repos_from_path();
}

std::vector<std::pair<std::vector<std::string>, bool>> & Context::get_libdnf_plugins_enablement() {
return p_impl->get_libdnf_plugins_enablement();
}

const std::vector<std::pair<std::vector<std::string>, bool>> & Context::get_libdnf_plugins_enablement() const {
return p_impl->get_libdnf_plugins_enablement();
}


Command::~Command() = default;

Expand Down
6 changes: 3 additions & 3 deletions dnf5/include/dnf5/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ class Context : public libdnf5::cli::session::Session {
/// Sets callbacks for repositories and loads them, updating metadata if necessary.
void load_repos(bool load_system);

/// list of lists of libdnf5 plugin names (global patterns) that we want to enable (true) or disable (false)
std::vector<std::pair<std::vector<std::string>, bool>> libdnf5_plugins_enablement;

void store_offline(libdnf5::base::Transaction & transaction);

// When set current transaction is not executed but rather stored to
Expand Down Expand Up @@ -160,6 +157,9 @@ class Context : public libdnf5::cli::session::Session {
std::vector<std::pair<std::string, std::string>> & get_repos_from_path();
const std::vector<std::pair<std::string, std::string>> & get_repos_from_path() const;

std::vector<std::pair<std::vector<std::string>, bool>> & get_libdnf_plugins_enablement();
const std::vector<std::pair<std::vector<std::string>, bool>> & get_libdnf_plugins_enablement() const;

private:
class Impl;
std::unique_ptr<Impl> p_impl;
Expand Down
43 changes: 40 additions & 3 deletions dnf5/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ void RootCommand::set_argument_parser() {
[&ctx](
[[maybe_unused]] ArgumentParser::NamedArg * arg, [[maybe_unused]] const char * option, const char * value) {
libdnf5::OptionStringList plugin_name_patterns(value);
ctx.libdnf5_plugins_enablement.emplace_back(plugin_name_patterns.get_value(), true);
ctx.get_libdnf_plugins_enablement().emplace_back(plugin_name_patterns.get_value(), true);
return true;
});
global_options_group->register_argument(enable_plugins_names);
Expand All @@ -456,7 +456,7 @@ void RootCommand::set_argument_parser() {
[&ctx](
[[maybe_unused]] ArgumentParser::NamedArg * arg, [[maybe_unused]] const char * option, const char * value) {
libdnf5::OptionStringList plugin_name_patterns(value);
ctx.libdnf5_plugins_enablement.emplace_back(plugin_name_patterns.get_value(), false);
ctx.get_libdnf_plugins_enablement().emplace_back(plugin_name_patterns.get_value(), false);
return true;
});
global_options_group->register_argument(disable_plugins_names);
Expand Down Expand Up @@ -1046,6 +1046,41 @@ static void print_resolve_hints(dnf5::Context & context) {
}
}

static void print_no_match_libdnf_plugin_patterns(dnf5::Context & context) {
if (!context.get_libdnf_plugins_enablement().empty()) {
std::vector<std::string> plugin_names;
for (const auto & plugin_info : context.get_base().get_plugins_info()) {
plugin_names.emplace_back(plugin_info.get_name());
}

struct {
const BgettextMessage no_match_message;
std::set<std::string> no_match_pattern_set;
} no_matches[2]{
{M_("No matches were found for the following plugin name patterns while enabling libdnf plugins: {}"), {}},
{M_("No matches were found for the following plugin name patterns while disabling libdnf plugins: {}"),
{}}};

for (const auto & [plugin_name_patterns, enable] : context.get_libdnf_plugins_enablement()) {
for (const auto & pattern : plugin_name_patterns) {
if (!libdnf5::sack::match_string(plugin_names, libdnf5::sack::QueryCmp::GLOB, pattern)) {
no_matches[enable ? 0 : 1].no_match_pattern_set.insert(pattern);
}
}
}

for (const auto & [no_match_message, no_match_pattern_set] : no_matches) {
if (auto it = no_match_pattern_set.begin(); it != no_match_pattern_set.end()) {
std::string patterns = *it++;
for (; it != no_match_pattern_set.end(); ++it) {
patterns += ", " + *it;
}
std::cerr << libdnf5::utils::sformat(TM_(no_match_message, 1), patterns) << std::endl;
}
}
}
}

int main(int argc, char * argv[]) try {
dnf5::set_locale();

Expand Down Expand Up @@ -1175,12 +1210,14 @@ int main(int argc, char * argv[]) try {

// Enable/disable libdnf5 plugins according to the list created by
// the --enable-plugin and --disable-plugin commandline arguments
for (const auto & [plugin_name_pattern, enable] : context.libdnf5_plugins_enablement) {
for (const auto & [plugin_name_pattern, enable] : context.get_libdnf_plugins_enablement()) {
base.enable_disable_plugins(plugin_name_pattern, enable);
}

base.setup();

print_no_match_libdnf_plugin_patterns(context);

auto destination_logger = libdnf5::create_rotating_file_logger(base, DNF5_LOGGER_FILENAME);
// Swap to destination logger
log_router.swap_logger(destination_logger, 0);
Expand Down
Loading