Skip to content

Commit

Permalink
Add debuginfo-install command
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mracek committed Jul 1, 2024
1 parent 19aa431 commit 0ccbed8
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 0 deletions.
79 changes: 79 additions & 0 deletions dnf5/commands/debuginfo-install/debuginfo-install.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
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 "debuginfo-install.hpp"

#include <libdnf5/conf/option_string.hpp>

#include <memory>


namespace dnf5 {


using namespace libdnf5::cli;


void DebuginfoInstallCommand::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("software_management_commands").register_argument(arg_parser_this_cmd);
}

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

get_argument_parser_command()->set_description("Install debuginfo packages.");

allow_erasing = std::make_unique<AllowErasingOption>(*this);
auto skip_broken = std::make_unique<SkipBrokenOption>(*this);
auto skip_unavailable = std::make_unique<SkipUnavailableOption>(*this);

patterns_to_debuginfo_install_options = parser.add_new_values();
auto patterns_arg = parser.add_new_positional_arg(
"patterns",
ArgumentParser::PositionalArg::AT_LEAST_ONE,
parser.add_init_value(std::unique_ptr<libdnf5::Option>(new libdnf5::OptionString(nullptr))),
patterns_to_debuginfo_install_options);
patterns_arg->set_description("Patterns");
cmd.register_positional_arg(patterns_arg);
}

void DebuginfoInstallCommand::configure() {
auto & context = get_context();
context.set_load_system_repo(true);
context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED);
context.get_base().get_repo_sack()->enable_debug_repos();
}

void DebuginfoInstallCommand::run() {
auto goal = get_context().get_goal();
auto settings = libdnf5::GoalJobSettings();
goal->set_allow_erasing(allow_erasing->get_value());

for (const auto & pattern : *patterns_to_debuginfo_install_options) {
auto option = dynamic_cast<libdnf5::OptionString *>(pattern.get());
goal->add_debug_install(option->get_value(), settings);
}
}

} // namespace dnf5
47 changes: 47 additions & 0 deletions dnf5/commands/debuginfo-install/debuginfo-install.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
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 DNF5_COMMANDS_DEBUGINFO_INSTALL_DEBUGINFO_INSTALL_HPP
#define DNF5_COMMANDS_DEBUGINFO_INSTALL_DEBUGINFO_INSTALL_HPP

#include <dnf5/context.hpp>
#include <dnf5/shared_options.hpp>

namespace dnf5 {


class DebuginfoInstallCommand : public Command {
public:
explicit DebuginfoInstallCommand(Context & context) : Command(context, "debuginfo-install") {}
void set_parent_command() override;
void set_argument_parser() override;
void configure() override;
void run() override;

std::vector<std::unique_ptr<libdnf5::Option>> * patterns_to_debuginfo_install_options{nullptr};

std::unique_ptr<AllowErasingOption> allow_erasing;
};


} // namespace dnf5


#endif // DNF5_COMMANDS_DEBUGINFO_INSTALL_DEBUGINFO_INSTALL_HPP
2 changes: 2 additions & 0 deletions dnf5/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#include "commands/check-upgrade/check-upgrade.hpp"
#include "commands/check/check.hpp"
#include "commands/clean/clean.hpp"
#include "commands/debuginfo-install/debuginfo-install.hpp"
#include "commands/distro-sync/distro-sync.hpp"
#include "commands/downgrade/downgrade.hpp"
#include "commands/download/download.hpp"
Expand Down Expand Up @@ -671,6 +672,7 @@ static void add_commands(Context & context) {
context.add_and_initialize_command(std::make_unique<DistroSyncCommand>(context));
context.add_and_initialize_command(std::make_unique<DowngradeCommand>(context));
context.add_and_initialize_command(std::make_unique<ReinstallCommand>(context));
context.add_and_initialize_command(std::make_unique<DebuginfoInstallCommand>(context));
context.add_and_initialize_command(std::make_unique<SwapCommand>(context));
context.add_and_initialize_command(std::make_unique<MarkCommand>(context));
context.add_and_initialize_command(std::make_unique<AutoremoveCommand>(context));
Expand Down

0 comments on commit 0ccbed8

Please sign in to comment.