Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added arch option to the download command #1206

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions dnf5/commands/download/download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

#include <libdnf5/conf/option_string.hpp>
#include <libdnf5/repo/package_downloader.hpp>
#include <libdnf5/rpm/arch.hpp>
#include <libdnf5/rpm/package.hpp>
#include <libdnf5/rpm/package_query.hpp>
#include <libdnf5/rpm/package_set.hpp>
#include <libdnf5/utils/bgettext/bgettext-mark-domain.h>

#include <algorithm>
#include <iostream>
#include <map>

Expand Down Expand Up @@ -104,12 +106,43 @@ void DownloadCommand::set_argument_parser() {
return true;
});

arch_option = {};
auto arch = parser.add_new_named_arg("arch");
arch->set_long_name("arch");
arch->set_description("Limit to packages of given architectures.");
arch->set_has_value(true);
arch->set_arg_value_help("ARCH,...");
arch->set_parse_hook_func(
[this](
[[maybe_unused]] ArgumentParser::NamedArg * arg, [[maybe_unused]] const char * option, const char * value) {
auto supported_arches = libdnf5::rpm::get_supported_arches();
if (std::find(supported_arches.begin(), supported_arches.end(), value) == supported_arches.end()) {
std::string available_arches{};
auto it = supported_arches.begin();
if (it != supported_arches.end()) {
available_arches.append("\"" + *it + "\"");
++it;
for (; it != supported_arches.end(); ++it) {
available_arches.append(", \"" + *it + "\"");
}
}
throw libdnf5::cli::ArgumentParserInvalidValueError(
M_("Unsupported architecture \"{0}\". Please choose one from {1}"),
std::string(value),
available_arches);
}
arch_option.emplace(value);
return true;
});


cmd.register_named_arg(alldeps);
create_destdir_option(*this);
cmd.register_named_arg(resolve);
cmd.register_positional_arg(keys);
cmd.register_named_arg(url);
cmd.register_named_arg(urlprotocol);
cmd.register_named_arg(arch);
}

void DownloadCommand::configure() {
Expand Down Expand Up @@ -150,6 +183,9 @@ void DownloadCommand::run() {
pkg_query.filter_available();
pkg_query.filter_priority();
pkg_query.filter_latest_evr();
if (!arch_option.empty()) {
pkg_query.filter_arch(std::vector<std::string>(arch_option.begin(), arch_option.end()));
}

for (const auto & pkg : pkg_query) {
download_pkgs.insert(create_nevra_pkg_pair(pkg));
Expand Down
1 change: 1 addition & 0 deletions dnf5/commands/download/download.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class DownloadCommand : public Command {
private:
std::set<std::string> urlprotocol_valid_options;
std::set<std::string> urlprotocol_option;
std::set<std::string> arch_option;
libdnf5::OptionBool * resolve_option{nullptr};
libdnf5::OptionBool * alldeps_option{nullptr};
libdnf5::OptionBool * url_option{nullptr};
Expand Down
7 changes: 6 additions & 1 deletion doc/commands/download.8.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ Options
``--urlprotocol``
| To be used together with ``--url``. It filters out the URLs to the specified protocols: ``http``, ``https``, ``ftp``, or ``file``. This option can be used multiple times.
``--arch``
| Limit to packages of given architectures. This option can be used multiple times.

Examples
Expand All @@ -71,7 +73,10 @@ Examples
| Download the ``maven-compiler-plugin`` package to ``/tmp/my_packages`` directory.
``dnf5 download --url --urlprotocol http python``
| List the http URL to download the python package
| List the http URL to download the python package.
``dnf5 download python --arch x86_64``
| Downloads python with the ``x86_64`` architecture.

See Also
Expand Down
Loading