forked from rpm-software-management/dnf5
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dnf5daemon: Add repo enable/disable client commands
Also create parent command where all related repo subcommands are located.
- Loading branch information
1 parent
3fad6ea
commit 4404696
Showing
7 changed files
with
267 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters