From 589114570d8ea2212f882c319b1ea50a638d7887 Mon Sep 17 00:00:00 2001 From: Marek Blaha Date: Thu, 28 Mar 2024 09:29:34 +0100 Subject: [PATCH] dnf5daemon-client: New switches for group list Adds support for new command line options: --hidden to show also hidden groups --avaiable to show only available groups (from repositories) --installed to show only installed groups --contains-pkgs to search for groups containing given packages --- .../commands/group/group_list.cpp | 25 +++++++++++++ .../commands/group/group_list.hpp | 36 +++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/dnf5daemon-client/commands/group/group_list.cpp b/dnf5daemon-client/commands/group/group_list.cpp index 88344c291..b429294ac 100644 --- a/dnf5daemon-client/commands/group/group_list.cpp +++ b/dnf5daemon-client/commands/group/group_list.cpp @@ -41,6 +41,12 @@ GroupListCommand::GroupListCommand(Context & context, const char * command) cmd.set_description("search for packages matching keyword"); + available = std::make_unique(*this); + installed = std::make_unique(*this); + available->arg->add_conflict_argument(*installed->arg); + hidden = std::make_unique(*this); + contains_pkgs = std::make_unique(*this); + patterns_options = parser.add_new_values(); auto keys = parser.add_new_positional_arg( "keys_to_match", @@ -76,6 +82,25 @@ void GroupListCommand::run() { } options["attributes"] = attributes; + if (hidden->get_value() || !patterns.empty()) { + options["with_hidden"] = true; + } + + std::string scope = "all"; + if (installed->get_value()) { + scope = "installed"; + } else if (available->get_value()) { + scope = "available"; + } + options["scope"] = scope; + + if (!contains_pkgs->get_value().empty()) { + options["contains_pkgs"] = contains_pkgs->get_value(); + } + + options["match_group_id"] = true; + options["match_group_name"] = true; + dnfdaemon::KeyValueMapList raw_groups; ctx.session_proxy->callMethod("list") .onInterface(dnfdaemon::INTERFACE_GROUP) diff --git a/dnf5daemon-client/commands/group/group_list.hpp b/dnf5daemon-client/commands/group/group_list.hpp index 9d2bfab98..031f01e46 100644 --- a/dnf5daemon-client/commands/group/group_list.hpp +++ b/dnf5daemon-client/commands/group/group_list.hpp @@ -22,13 +22,45 @@ along with libdnf. If not, see . #include "commands/command.hpp" +#include #include +#include #include #include namespace dnfdaemon::client { +class GroupAvailableOption : public libdnf5::cli::session::BoolOption { +public: + explicit GroupAvailableOption(libdnf5::cli::session::Command & command) + : BoolOption(command, "available", '\0', _("Show only available groups."), false) {} +}; + +class GroupInstalledOption : public libdnf5::cli::session::BoolOption { +public: + explicit GroupInstalledOption(libdnf5::cli::session::Command & command) + : BoolOption(command, "installed", '\0', _("Show only installed groups."), false) {} +}; + +class GroupHiddenOption : public libdnf5::cli::session::BoolOption { +public: + explicit GroupHiddenOption(libdnf5::cli::session::Command & command) + : BoolOption(command, "hidden", '\0', _("Show also hidden groups."), false) {} +}; + +class GroupContainPkgsOption : public libdnf5::cli::session::AppendStringListOption { +public: + explicit GroupContainPkgsOption(libdnf5::cli::session::Command & command) + : AppendStringListOption( + command, + "contains-pkgs", + '\0', + _("Show only groups containing packages with specified names. List option, supports globs."), + "PACKAGE_NAME,...") {} +}; + + class GroupListCommand : public DaemonCommand { public: explicit GroupListCommand(Context & context, const char * command); @@ -36,6 +68,10 @@ class GroupListCommand : public DaemonCommand { private: std::vector> * patterns_options{nullptr}; + std::unique_ptr hidden{nullptr}; + std::unique_ptr available{nullptr}; + std::unique_ptr installed{nullptr}; + std::unique_ptr contains_pkgs{nullptr}; const std::string command; };