diff --git a/dnf5daemon-client/commands/command.cpp b/dnf5daemon-client/commands/command.cpp index 75acb8bd8..67a4e8ea2 100644 --- a/dnf5daemon-client/commands/command.cpp +++ b/dnf5daemon-client/commands/command.cpp @@ -37,7 +37,7 @@ along with libdnf. If not, see . namespace dnfdaemon::client { -void TransactionCommand::run_transaction() { +void TransactionCommand::run_transaction(bool offline) { auto & ctx = get_context(); dnfdaemon::KeyValueMap options = {}; @@ -80,6 +80,7 @@ void TransactionCommand::run_transaction() { // do the transaction options.clear(); + options["offline"] = offline; ctx.session_proxy->callMethod("do_transaction") .onInterface(dnfdaemon::INTERFACE_GOAL) .withTimeout(static_cast(-1)) diff --git a/dnf5daemon-client/commands/command.hpp b/dnf5daemon-client/commands/command.hpp index 1a32e21a8..2187d80bb 100644 --- a/dnf5daemon-client/commands/command.hpp +++ b/dnf5daemon-client/commands/command.hpp @@ -42,7 +42,7 @@ class DaemonCommand : public libdnf5::cli::session::Command { class TransactionCommand : public DaemonCommand { public: explicit TransactionCommand(Context & context, const std::string & name) : DaemonCommand(context, name){}; - void run_transaction(); + void run_transaction(bool offline = false); }; diff --git a/dnf5daemon-client/commands/distro-sync/distro-sync.cpp b/dnf5daemon-client/commands/distro-sync/distro-sync.cpp index 4b026425a..8b1d0741c 100644 --- a/dnf5daemon-client/commands/distro-sync/distro-sync.cpp +++ b/dnf5daemon-client/commands/distro-sync/distro-sync.cpp @@ -49,6 +49,9 @@ void DistroSyncCommand::set_argument_parser() { auto specs_arg = pkg_specs_argument(parser, libdnf5::cli::ArgumentParser::PositionalArg::UNLIMITED, pkg_specs); specs_arg->set_description("Patterns"); cmd.register_positional_arg(specs_arg); + + auto offline_arg = create_offline_option(parser, &offline_option); + cmd.register_named_arg(offline_arg); } void DistroSyncCommand::run() { @@ -65,7 +68,7 @@ void DistroSyncCommand::run() { .withTimeout(static_cast(-1)) .withArguments(pkg_specs, options); - run_transaction(); + run_transaction(offline_option.get_value()); } } // namespace dnfdaemon::client diff --git a/dnf5daemon-client/commands/distro-sync/distro-sync.hpp b/dnf5daemon-client/commands/distro-sync/distro-sync.hpp index 1ab69aae8..646d9a516 100644 --- a/dnf5daemon-client/commands/distro-sync/distro-sync.hpp +++ b/dnf5daemon-client/commands/distro-sync/distro-sync.hpp @@ -22,7 +22,7 @@ along with libdnf. If not, see . #include "commands/command.hpp" -#include +#include namespace dnfdaemon::client { @@ -35,6 +35,7 @@ class DistroSyncCommand : public TransactionCommand { private: std::vector pkg_specs; + libdnf5::OptionBool offline_option{false}; }; } // namespace dnfdaemon::client diff --git a/dnf5daemon-client/commands/downgrade/downgrade.cpp b/dnf5daemon-client/commands/downgrade/downgrade.cpp index e56047e49..0bcfaff13 100644 --- a/dnf5daemon-client/commands/downgrade/downgrade.cpp +++ b/dnf5daemon-client/commands/downgrade/downgrade.cpp @@ -49,6 +49,9 @@ void DowngradeCommand::set_argument_parser() { auto specs_arg = pkg_specs_argument(parser, libdnf5::cli::ArgumentParser::PositionalArg::AT_LEAST_ONE, pkg_specs); specs_arg->set_description("List of packages to downgrade"); cmd.register_positional_arg(specs_arg); + + auto offline_arg = create_offline_option(parser, &offline_option); + cmd.register_named_arg(offline_arg); } void DowngradeCommand::run() { @@ -65,7 +68,7 @@ void DowngradeCommand::run() { .withTimeout(static_cast(-1)) .withArguments(pkg_specs, options); - run_transaction(); + run_transaction(offline_option.get_value()); } } // namespace dnfdaemon::client diff --git a/dnf5daemon-client/commands/downgrade/downgrade.hpp b/dnf5daemon-client/commands/downgrade/downgrade.hpp index 21435edbb..e11de3eef 100644 --- a/dnf5daemon-client/commands/downgrade/downgrade.hpp +++ b/dnf5daemon-client/commands/downgrade/downgrade.hpp @@ -22,7 +22,7 @@ along with libdnf. If not, see . #include "commands/command.hpp" -#include +#include namespace dnfdaemon::client { @@ -35,6 +35,7 @@ class DowngradeCommand : public TransactionCommand { private: std::vector pkg_specs{}; + libdnf5::OptionBool offline_option{false}; }; } // namespace dnfdaemon::client diff --git a/dnf5daemon-client/commands/install/install.cpp b/dnf5daemon-client/commands/install/install.cpp index 9d2338905..4dba94f50 100644 --- a/dnf5daemon-client/commands/install/install.cpp +++ b/dnf5daemon-client/commands/install/install.cpp @@ -62,6 +62,9 @@ void InstallCommand::set_argument_parser() { skip_unavailable->link_value(&skip_unavailable_option); cmd.register_named_arg(skip_unavailable); + auto offline_arg = create_offline_option(parser, &offline_option); + cmd.register_named_arg(offline_arg); + auto specs_arg = pkg_specs_argument(parser, libdnf5::cli::ArgumentParser::PositionalArg::AT_LEAST_ONE, pkg_specs); specs_arg->set_description("List of packages to install"); cmd.register_positional_arg(specs_arg); @@ -88,7 +91,7 @@ void InstallCommand::run() { .withTimeout(static_cast(-1)) .withArguments(pkg_specs, options); - run_transaction(); + run_transaction(offline_option.get_value()); } } // namespace dnfdaemon::client diff --git a/dnf5daemon-client/commands/install/install.hpp b/dnf5daemon-client/commands/install/install.hpp index 18569bfc9..d567edb81 100644 --- a/dnf5daemon-client/commands/install/install.hpp +++ b/dnf5daemon-client/commands/install/install.hpp @@ -22,7 +22,6 @@ along with libdnf. If not, see . #include "commands/command.hpp" -#include #include namespace dnfdaemon::client { @@ -35,9 +34,10 @@ class InstallCommand : public TransactionCommand { void run() override; private: + std::vector pkg_specs{}; libdnf5::OptionBool skip_broken_option{false}; libdnf5::OptionBool skip_unavailable_option{false}; - std::vector pkg_specs{}; + libdnf5::OptionBool offline_option{false}; }; } // namespace dnfdaemon::client diff --git a/dnf5daemon-client/commands/reinstall/reinstall.cpp b/dnf5daemon-client/commands/reinstall/reinstall.cpp index e5fbf9d11..91624021c 100644 --- a/dnf5daemon-client/commands/reinstall/reinstall.cpp +++ b/dnf5daemon-client/commands/reinstall/reinstall.cpp @@ -49,6 +49,9 @@ void ReinstallCommand::set_argument_parser() { auto specs_arg = pkg_specs_argument(parser, libdnf5::cli::ArgumentParser::PositionalArg::AT_LEAST_ONE, pkg_specs); specs_arg->set_description("List of packages to reinstall"); cmd.register_positional_arg(specs_arg); + + auto offline_arg = create_offline_option(parser, &offline_option); + cmd.register_named_arg(offline_arg); } void ReinstallCommand::run() { @@ -65,7 +68,7 @@ void ReinstallCommand::run() { .withTimeout(static_cast(-1)) .withArguments(pkg_specs, options); - run_transaction(); + run_transaction(offline_option.get_value()); } } // namespace dnfdaemon::client diff --git a/dnf5daemon-client/commands/reinstall/reinstall.hpp b/dnf5daemon-client/commands/reinstall/reinstall.hpp index 395b9644d..689b957f0 100644 --- a/dnf5daemon-client/commands/reinstall/reinstall.hpp +++ b/dnf5daemon-client/commands/reinstall/reinstall.hpp @@ -22,7 +22,7 @@ along with libdnf. If not, see . #include "commands/command.hpp" -#include +#include namespace dnfdaemon::client { @@ -35,6 +35,7 @@ class ReinstallCommand : public TransactionCommand { private: std::vector pkg_specs{}; + libdnf5::OptionBool offline_option{false}; }; } // namespace dnfdaemon::client diff --git a/dnf5daemon-client/commands/remove/remove.cpp b/dnf5daemon-client/commands/remove/remove.cpp index 41c3826bb..6fcfa45db 100644 --- a/dnf5daemon-client/commands/remove/remove.cpp +++ b/dnf5daemon-client/commands/remove/remove.cpp @@ -51,6 +51,9 @@ void RemoveCommand::set_argument_parser() { specs_arg->set_description("List of packages to remove"); cmd.register_positional_arg(specs_arg); + auto offline_arg = create_offline_option(parser, &offline_option); + cmd.register_named_arg(offline_arg); + // run remove command always with allow_erasing on context.allow_erasing.set(libdnf5::Option::Priority::RUNTIME, true); } @@ -69,7 +72,7 @@ void RemoveCommand::run() { .withTimeout(static_cast(-1)) .withArguments(pkg_specs, options); - run_transaction(); + run_transaction(offline_option.get_value()); } } // namespace dnfdaemon::client diff --git a/dnf5daemon-client/commands/remove/remove.hpp b/dnf5daemon-client/commands/remove/remove.hpp index 77d52bf87..95229d440 100644 --- a/dnf5daemon-client/commands/remove/remove.hpp +++ b/dnf5daemon-client/commands/remove/remove.hpp @@ -22,7 +22,7 @@ along with libdnf. If not, see . #include "commands/command.hpp" -#include +#include namespace dnfdaemon::client { @@ -35,6 +35,7 @@ class RemoveCommand : public TransactionCommand { private: std::vector pkg_specs{}; + libdnf5::OptionBool offline_option{false}; }; } // namespace dnfdaemon::client diff --git a/dnf5daemon-client/commands/shared_options.cpp b/dnf5daemon-client/commands/shared_options.cpp index d40923523..409babe80 100644 --- a/dnf5daemon-client/commands/shared_options.cpp +++ b/dnf5daemon-client/commands/shared_options.cpp @@ -21,8 +21,12 @@ along with libdnf. If not, see . #include "utils/url.hpp" +#include + #include +namespace { + static void normalize_paths(int specs_count, const char * const specs[], std::vector & pkg_specs) { const std::string_view ext(".rpm"); std::set unique_items; @@ -39,6 +43,10 @@ static void normalize_paths(int specs_count, const char * const specs[], std::ve } } +} // anonymous namespace + +namespace dnfdaemon::client { + libdnf5::cli::ArgumentParser::PositionalArg * pkg_specs_argument( libdnf5::cli::ArgumentParser & parser, int nargs, std::vector & pkg_specs) { auto specs = parser.add_new_positional_arg("pkg_specs", nargs, nullptr, nullptr); @@ -49,3 +57,15 @@ libdnf5::cli::ArgumentParser::PositionalArg * pkg_specs_argument( }); return specs; } + +libdnf5::cli::ArgumentParser::NamedArg * create_offline_option( + libdnf5::cli::ArgumentParser & parser, libdnf5::Option * value) { + auto offline = parser.add_new_named_arg("offline"); + offline->set_long_name("offline"); + offline->set_description("Store the transaction to be performed offline"); + offline->set_const_value("true"); + offline->link_value(value); + return offline; +} + +} // namespace dnfdaemon::client diff --git a/dnf5daemon-client/commands/shared_options.hpp b/dnf5daemon-client/commands/shared_options.hpp index 29e932156..8712cb73d 100644 --- a/dnf5daemon-client/commands/shared_options.hpp +++ b/dnf5daemon-client/commands/shared_options.hpp @@ -22,7 +22,14 @@ along with libdnf. If not, see . #include +namespace dnfdaemon::client { + libdnf5::cli::ArgumentParser::PositionalArg * pkg_specs_argument( libdnf5::cli::ArgumentParser & parser, int nargs, std::vector & pkg_specs); +/// Create the `--offline` named arg bound to the given option +libdnf5::cli::ArgumentParser::NamedArg * create_offline_option( + libdnf5::cli::ArgumentParser & parser, libdnf5::Option * value); + +} // namespace dnfdaemon::client #endif diff --git a/dnf5daemon-client/commands/upgrade/upgrade.cpp b/dnf5daemon-client/commands/upgrade/upgrade.cpp index 047d6a7ea..884ca8658 100644 --- a/dnf5daemon-client/commands/upgrade/upgrade.cpp +++ b/dnf5daemon-client/commands/upgrade/upgrade.cpp @@ -49,6 +49,9 @@ void UpgradeCommand::set_argument_parser() { auto specs_arg = pkg_specs_argument(parser, libdnf5::cli::ArgumentParser::PositionalArg::UNLIMITED, pkg_specs); specs_arg->set_description("List of packages to upgrade"); cmd.register_positional_arg(specs_arg); + + auto offline_arg = create_offline_option(parser, &offline_option); + cmd.register_named_arg(offline_arg); } void UpgradeCommand::run() { @@ -59,13 +62,12 @@ void UpgradeCommand::run() { } dnfdaemon::KeyValueMap options = {}; - ctx.session_proxy->callMethod("upgrade") .onInterface(dnfdaemon::INTERFACE_RPM) .withTimeout(static_cast(-1)) .withArguments(pkg_specs, options); - run_transaction(); + run_transaction(offline_option.get_value()); } } // namespace dnfdaemon::client diff --git a/dnf5daemon-client/commands/upgrade/upgrade.hpp b/dnf5daemon-client/commands/upgrade/upgrade.hpp index 05f81557c..0a26070d5 100644 --- a/dnf5daemon-client/commands/upgrade/upgrade.hpp +++ b/dnf5daemon-client/commands/upgrade/upgrade.hpp @@ -22,7 +22,7 @@ along with libdnf. If not, see . #include "commands/command.hpp" -#include +#include namespace dnfdaemon::client { @@ -35,6 +35,7 @@ class UpgradeCommand : public TransactionCommand { private: std::vector pkg_specs{}; + libdnf5::OptionBool offline_option{false}; }; } // namespace dnfdaemon::client