Skip to content

Commit 9fec3d6

Browse files
pkratochppisar
authored andcommitted
comps: Add environment install, remove and upgrade commands
The environment commands can also install groups, but prefer environments in case the spec matches both. Similarly, the group commands can also install environments, but prefer groups.
1 parent 023e4ce commit 9fec3d6

File tree

13 files changed

+215
-8
lines changed

13 files changed

+215
-8
lines changed

dnf5/commands/environment/environment.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
#include "environment.hpp"
2121

2222
#include "environment_info.hpp"
23+
#include "environment_install.hpp"
2324
#include "environment_list.hpp"
25+
#include "environment_remove.hpp"
26+
#include "environment_upgrade.hpp"
2427

2528
namespace dnf5 {
2629

@@ -36,11 +39,20 @@ void EnvironmentCommand::set_argument_parser() {
3639
}
3740

3841
void EnvironmentCommand::register_subcommands() {
42+
// query commands
3943
auto * query_commands_environment = get_context().get_argument_parser().add_new_group("environment_query_commands");
4044
query_commands_environment->set_header("Query Commands:");
4145
get_argument_parser_command()->register_group(query_commands_environment);
4246
register_subcommand(std::make_unique<EnvironmentListCommand>(get_context()), query_commands_environment);
4347
register_subcommand(std::make_unique<EnvironmentInfoCommand>(get_context()), query_commands_environment);
48+
// software management commands
49+
auto * swm_commands_environment =
50+
get_context().get_argument_parser().add_new_group("environment_software_management_commands");
51+
swm_commands_environment->set_header("Software Management Commands:");
52+
get_argument_parser_command()->register_group(swm_commands_environment);
53+
register_subcommand(std::make_unique<EnvironmentInstallCommand>(get_context()), swm_commands_environment);
54+
register_subcommand(std::make_unique<EnvironmentRemoveCommand>(get_context()), swm_commands_environment);
55+
register_subcommand(std::make_unique<EnvironmentUpgradeCommand>(get_context()), swm_commands_environment);
4456
}
4557

4658
void EnvironmentCommand::pre_configure() {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright Contributors to the DNF5 project
2+
// SPDX-License-Identifier: LGPL-2.1-or-later
3+
4+
#ifndef DNF5_COMMANDS_ENVIRONMENT_ENVIRONMENT_INSTALL_HPP
5+
#define DNF5_COMMANDS_ENVIRONMENT_ENVIRONMENT_INSTALL_HPP
6+
7+
#include "../group/group_install.hpp"
8+
9+
#include <dnf5/context.hpp>
10+
11+
12+
namespace dnf5 {
13+
14+
15+
class EnvironmentInstallCommand : public GroupInstallCommand {
16+
public:
17+
explicit EnvironmentInstallCommand(Context & context) : GroupInstallCommand(context) {}
18+
19+
protected:
20+
const libdnf5::CompsTypePreferred & get_comps_type_preferred() const override { return comps_type_preferred; }
21+
22+
private:
23+
static inline constexpr libdnf5::CompsTypePreferred comps_type_preferred = libdnf5::CompsTypePreferred::ENVIRONMENT;
24+
};
25+
26+
27+
} // namespace dnf5
28+
29+
30+
#endif // DNF5_COMMANDS_ENVIRONMENT_ENVIRONMENT_INSTALL_HPP
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright Contributors to the DNF5 project
2+
// SPDX-License-Identifier: LGPL-2.1-or-later
3+
4+
#ifndef DNF5_COMMANDS_ENVIRONMENT_ENVIRONMENT_REMOVE_HPP
5+
#define DNF5_COMMANDS_ENVIRONMENT_ENVIRONMENT_REMOVE_HPP
6+
7+
#include "../group/group_remove.hpp"
8+
9+
#include <dnf5/context.hpp>
10+
11+
12+
namespace dnf5 {
13+
14+
15+
class EnvironmentRemoveCommand : public GroupRemoveCommand {
16+
public:
17+
explicit EnvironmentRemoveCommand(Context & context) : GroupRemoveCommand(context) {}
18+
19+
protected:
20+
const libdnf5::CompsTypePreferred & get_comps_type_preferred() const override { return comps_type_preferred; }
21+
22+
private:
23+
static inline constexpr libdnf5::CompsTypePreferred comps_type_preferred = libdnf5::CompsTypePreferred::ENVIRONMENT;
24+
};
25+
26+
27+
} // namespace dnf5
28+
29+
30+
#endif // DNF5_COMMANDS_ENVIRONMENT_ENVIRONMENT_REMOVE_HPP
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright Contributors to the DNF5 project
2+
// SPDX-License-Identifier: LGPL-2.1-or-later
3+
4+
#ifndef DNF5_COMMANDS_ENVIRONMENT_ENVIRONMENT_UPGRADE_HPP
5+
#define DNF5_COMMANDS_ENVIRONMENT_ENVIRONMENT_UPGRADE_HPP
6+
7+
#include "../group/group_upgrade.hpp"
8+
9+
#include <dnf5/context.hpp>
10+
11+
12+
namespace dnf5 {
13+
14+
15+
class EnvironmentUpgradeCommand : public GroupUpgradeCommand {
16+
public:
17+
explicit EnvironmentUpgradeCommand(Context & context) : GroupUpgradeCommand(context) {}
18+
19+
protected:
20+
const libdnf5::CompsTypePreferred & get_comps_type_preferred() const override { return comps_type_preferred; }
21+
22+
private:
23+
static inline constexpr libdnf5::CompsTypePreferred comps_type_preferred = libdnf5::CompsTypePreferred::ENVIRONMENT;
24+
};
25+
26+
27+
} // namespace dnf5
28+
29+
30+
#endif // DNF5_COMMANDS_ENVIRONMENT_ENVIRONMENT_UPGRADE_HPP

dnf5/commands/group/group_install.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ void GroupInstallCommand::run() {
6969
ctx.get_base().get_config().get_group_package_types_option().get_value());
7070
settings.set_group_package_types(group_package_types | libdnf5::comps::PackageType::OPTIONAL);
7171
}
72+
settings.set_comps_type_preferred(get_comps_type_preferred());
7273
for (const auto & spec : group_specs->get_value()) {
7374
goal->add_group_install(spec, libdnf5::transaction::TransactionItemReason::USER, settings);
7475
}

dnf5/commands/group/group_install.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ class GroupInstallCommand : public Command {
4848
protected:
4949
// to be used by an alias command only
5050
explicit GroupInstallCommand(Context & context, const std::string & name) : Command(context, name) {}
51+
52+
virtual const libdnf5::CompsTypePreferred & get_comps_type_preferred() const { return comps_type_preferred; }
53+
54+
private:
55+
libdnf5::CompsTypePreferred comps_type_preferred = libdnf5::CompsTypePreferred::GROUP;
5156
};
5257

5358

dnf5/commands/group/group_remove.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ void GroupRemoveCommand::run() {
5454
if (no_packages->get_value()) {
5555
settings.set_group_no_packages(true);
5656
}
57+
settings.set_comps_type_preferred(get_comps_type_preferred());
5758
for (const auto & spec : group_specs->get_value()) {
5859
goal->add_group_remove(spec, libdnf5::transaction::TransactionItemReason::USER, settings);
5960
}

dnf5/commands/group/group_remove.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ class GroupRemoveCommand : public Command {
4141
protected:
4242
// to be used by an alias command only
4343
explicit GroupRemoveCommand(Context & context, const std::string & name) : Command(context, name) {}
44+
45+
virtual const libdnf5::CompsTypePreferred & get_comps_type_preferred() const { return comps_type_preferred; }
46+
47+
private:
48+
libdnf5::CompsTypePreferred comps_type_preferred = libdnf5::CompsTypePreferred::GROUP;
4449
};
4550

4651

dnf5/commands/group/group_upgrade.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ void GroupUpgradeCommand::run() {
5858
goal->set_allow_erasing(allow_erasing->get_value());
5959

6060
libdnf5::GoalJobSettings settings;
61+
settings.set_comps_type_preferred(get_comps_type_preferred());
6162
for (const auto & spec : group_specs->get_value()) {
6263
goal->add_group_upgrade(spec, settings);
6364
}

dnf5/commands/group/group_upgrade.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ class GroupUpgradeCommand : public Command {
4242
std::unique_ptr<AllowErasingOption> allow_erasing;
4343

4444
std::unique_ptr<CompsSpecArguments> group_specs{nullptr};
45+
46+
protected:
47+
virtual const libdnf5::CompsTypePreferred & get_comps_type_preferred() const { return comps_type_preferred; }
48+
49+
private:
50+
libdnf5::CompsTypePreferred comps_type_preferred = libdnf5::CompsTypePreferred::GROUP;
4551
};
4652

4753

0 commit comments

Comments
 (0)