Skip to content

Commit

Permalink
dnf5daemon: Add repo enable/disable client commands
Browse files Browse the repository at this point in the history
Also create parent command where all related repo subcommands are located.
  • Loading branch information
jan-kolarik authored and m-blaha committed Mar 6, 2024
1 parent 3fad6ea commit 4404696
Show file tree
Hide file tree
Showing 7 changed files with 267 additions and 0 deletions.
50 changes: 50 additions & 0 deletions dnf5daemon-client/commands/repo/repo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Copyright Contributors to the libdnf project.
This file is part of libdnf: https://github.com/rpm-software-management/libdnf/
Libdnf is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
Libdnf is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with libdnf. If not, see <https://www.gnu.org/licenses/>.
*/

#include "repo.hpp"

#include "repo_disable.hpp"
#include "repo_enable.hpp"

namespace dnfdaemon::client {

void RepoCommand::set_parent_command() {
auto * arg_parser_parent_cmd = get_session().get_argument_parser().get_root_command();
auto * arg_parser_this_cmd = get_argument_parser_command();
arg_parser_parent_cmd->register_command(arg_parser_this_cmd);
arg_parser_parent_cmd->get_group("subcommands").register_argument(arg_parser_this_cmd);
}

void RepoCommand::set_argument_parser() {
get_argument_parser_command()->set_description("Manage repositories");
}

void RepoCommand::register_subcommands() {
auto * config_commands_repo = get_context().get_argument_parser().add_new_group("repo_config_commands");
config_commands_repo->set_header("Configuration Commands:");
get_argument_parser_command()->register_group(config_commands_repo);
register_subcommand(std::make_unique<RepoEnableCommand>(get_context()), config_commands_repo);
register_subcommand(std::make_unique<RepoDisableCommand>(get_context()), config_commands_repo);
}

void RepoCommand::pre_configure() {
throw_missing_command();
}

} // namespace dnfdaemon::client
40 changes: 40 additions & 0 deletions dnf5daemon-client/commands/repo/repo.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright Contributors to the libdnf project.
This file is part of libdnf: https://github.com/rpm-software-management/libdnf/
Libdnf is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
Libdnf is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with libdnf. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef DNF5DAEMON_CLIENT_COMMANDS_REPO_REPO_HPP
#define DNF5DAEMON_CLIENT_COMMANDS_REPO_REPO_HPP

#include "commands/command.hpp"
#include "context.hpp"

namespace dnfdaemon::client {

class RepoCommand : public DaemonCommand {
public:
explicit RepoCommand(Context & context) : DaemonCommand(context, "repo") {}
void set_parent_command() override;
void set_argument_parser() override;
void register_subcommands() override;
void pre_configure() override;
};

} // namespace dnfdaemon::client


#endif // DNF5DAEMON_CLIENT_COMMANDS_REPO_REPO_HPP
35 changes: 35 additions & 0 deletions dnf5daemon-client/commands/repo/repo_disable.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Copyright Contributors to the libdnf project.
This file is part of libdnf: https://github.com/rpm-software-management/libdnf/
Libdnf is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
Libdnf is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with libdnf. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef DNF5DAEMON_CLIENT_COMMANDS_REPO_DISABLE_HPP
#define DNF5DAEMON_CLIENT_COMMANDS_REPO_DISABLE_HPP

#include "commands/command.hpp"
#include "repo_enable_disable.hpp"

namespace dnfdaemon::client {

class RepoDisableCommand : public RepoEnableDisableCommand {
public:
explicit RepoDisableCommand(Context & context) : RepoEnableDisableCommand(context, "disable") {}
};

} // namespace dnfdaemon::client

#endif // DNF5DAEMON_CLIENT_COMMANDS_REPO_DISABLE_HPP
35 changes: 35 additions & 0 deletions dnf5daemon-client/commands/repo/repo_enable.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Copyright Contributors to the libdnf project.
This file is part of libdnf: https://github.com/rpm-software-management/libdnf/
Libdnf is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
Libdnf is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with libdnf. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef DNF5DAEMON_CLIENT_COMMANDS_REPO_ENABLE_HPP
#define DNF5DAEMON_CLIENT_COMMANDS_REPO_ENABLE_HPP

#include "commands/command.hpp"
#include "repo_enable_disable.hpp"

namespace dnfdaemon::client {

class RepoEnableCommand : public RepoEnableDisableCommand {
public:
explicit RepoEnableCommand(Context & context) : RepoEnableDisableCommand(context, "enable") {}
};

} // namespace dnfdaemon::client

#endif // DNF5DAEMON_CLIENT_COMMANDS_REPO_ENABLE_HPP
62 changes: 62 additions & 0 deletions dnf5daemon-client/commands/repo/repo_enable_disable.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
Copyright Contributors to the libdnf project.
This file is part of libdnf: https://github.com/rpm-software-management/libdnf/
Libdnf is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
Libdnf is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with libdnf. If not, see <https://www.gnu.org/licenses/>.
*/

#include "repo_enable_disable.hpp"

#include <fmt/format.h>

namespace dnfdaemon::client {

using namespace libdnf5::cli;

void RepoEnableDisableCommand::set_argument_parser() {
auto & parser = get_context().get_argument_parser();
auto & cmd = *get_argument_parser_command();

patterns_options = parser.add_new_values();
auto repos = parser.add_new_positional_arg(
"repo_ids",
libdnf5::cli::ArgumentParser::PositionalArg::UNLIMITED,
parser.add_init_value(std::unique_ptr<libdnf5::Option>(new libdnf5::OptionString(nullptr))),
patterns_options);

repos->set_description(fmt::format("List of repos to be {}d", command));
cmd.set_description(fmt::format("{} given repositories", command));
cmd.register_positional_arg(repos);
}

void RepoEnableDisableCommand::run() {
auto & ctx = get_context();

std::vector<std::string> patterns;
if (!patterns_options->empty()) {
patterns.reserve(patterns_options->size());
for (auto & pattern : *patterns_options) {
auto option = dynamic_cast<libdnf5::OptionString *>(pattern.get());
patterns.emplace_back(option->get_value());
}
}

ctx.session_proxy->callMethod(command)
.onInterface(dnfdaemon::INTERFACE_REPO)
.withTimeout(static_cast<uint64_t>(-1))
.withArguments(patterns);
}

} // namespace dnfdaemon::client
42 changes: 42 additions & 0 deletions dnf5daemon-client/commands/repo/repo_enable_disable.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright Contributors to the libdnf project.
This file is part of libdnf: https://github.com/rpm-software-management/libdnf/
Libdnf is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
Libdnf is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with libdnf. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef DNF5DAEMON_CLIENT_COMMANDS_REPO_ENABLE_DISABLE_HPP
#define DNF5DAEMON_CLIENT_COMMANDS_REPO_ENABLE_DISABLE_HPP

#include "commands/command.hpp"

namespace dnfdaemon::client {

class RepoEnableDisableCommand : public DaemonCommand {
public:
explicit RepoEnableDisableCommand(Context & context, const std::string & command)
: DaemonCommand(context, command),
command(command) {}
void set_argument_parser() override;
void run() override;

private:
std::vector<std::unique_ptr<libdnf5::Option>> * patterns_options{nullptr};
const std::string command;
};

} // namespace dnfdaemon::client

#endif // DNF5DAEMON_CLIENT_COMMANDS_REPO_ENABLE_DISABLE_HPP
3 changes: 3 additions & 0 deletions dnf5daemon-client/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#include "commands/install/install.hpp"
#include "commands/reinstall/reinstall.hpp"
#include "commands/remove/remove.hpp"
#include "commands/repo/repo.hpp"
#include "commands/repolist/repolist.hpp"
#include "commands/repoquery/repoquery.hpp"
#include "commands/upgrade/upgrade.hpp"
Expand Down Expand Up @@ -202,6 +203,8 @@ static void add_commands(Context & context) {

context.add_and_initialize_command(std::make_unique<GroupCommand>(context));

context.add_and_initialize_command(std::make_unique<RepoCommand>(context));

context.add_and_initialize_command(std::make_unique<RepolistCommand>(context, "repolist"));
context.add_and_initialize_command(std::make_unique<RepolistCommand>(context, "repoinfo"));

Expand Down

0 comments on commit 4404696

Please sign in to comment.