Skip to content

Commit

Permalink
dnf5daemon-client: New switches for group list
Browse files Browse the repository at this point in the history
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
  • Loading branch information
m-blaha authored and pkratoch committed Apr 3, 2024
1 parent e4cddf9 commit 5891145
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
25 changes: 25 additions & 0 deletions dnf5daemon-client/commands/group/group_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ GroupListCommand::GroupListCommand(Context & context, const char * command)

cmd.set_description("search for packages matching keyword");

available = std::make_unique<GroupAvailableOption>(*this);
installed = std::make_unique<GroupInstalledOption>(*this);
available->arg->add_conflict_argument(*installed->arg);
hidden = std::make_unique<GroupHiddenOption>(*this);
contains_pkgs = std::make_unique<GroupContainPkgsOption>(*this);

patterns_options = parser.add_new_values();
auto keys = parser.add_new_positional_arg(
"keys_to_match",
Expand Down Expand Up @@ -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)
Expand Down
36 changes: 36 additions & 0 deletions dnf5daemon-client/commands/group/group_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,56 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

#include "commands/command.hpp"

#include <libdnf5-cli/session.hpp>
#include <libdnf5/conf/option_enum.hpp>
#include <libdnf5/utils/bgettext/bgettext-lib.h>

#include <memory>
#include <vector>

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);
void run() override;

private:
std::vector<std::unique_ptr<libdnf5::Option>> * patterns_options{nullptr};
std::unique_ptr<GroupHiddenOption> hidden{nullptr};
std::unique_ptr<GroupAvailableOption> available{nullptr};
std::unique_ptr<GroupInstalledOption> installed{nullptr};
std::unique_ptr<GroupContainPkgsOption> contains_pkgs{nullptr};
const std::string command;
};

Expand Down

0 comments on commit 5891145

Please sign in to comment.