Skip to content

Commit

Permalink
[DNF5] --enable-plugin and --disable-pluin: no match found message
Browse files Browse the repository at this point in the history
Print a warning if no libdnf plugin with a matching name is found.
  • Loading branch information
jrohel authored and jan-kolarik committed Apr 24, 2024
1 parent 00a699a commit a016832
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions dnf5/main.cpp
Original file line number Diff line number Diff line change
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 @@ -1181,6 +1216,8 @@ int main(int argc, char * argv[]) try {

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

0 comments on commit a016832

Please sign in to comment.