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

Add --allmirros option for dnf download --url #1735

Merged
merged 1 commit into from
Oct 1, 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
18 changes: 17 additions & 1 deletion dnf5/commands/download/download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ void DownloadCommand::set_argument_parser() {
url_option = dynamic_cast<libdnf5::OptionBool *>(
parser.add_init_value(std::unique_ptr<libdnf5::OptionBool>(new libdnf5::OptionBool(false))));

allmirrors_option = dynamic_cast<libdnf5::OptionBool *>(
parser.add_init_value(std::unique_ptr<libdnf5::OptionBool>(new libdnf5::OptionBool(false))));

srpm_option = dynamic_cast<libdnf5::OptionBool *>(
parser.add_init_value(std::unique_ptr<libdnf5::OptionBool>(new libdnf5::OptionBool(false))));

Expand Down Expand Up @@ -97,6 +100,12 @@ void DownloadCommand::set_argument_parser() {
url->set_const_value("true");
url->link_value(url_option);

auto allmirrors = parser.add_new_named_arg("allmirrors");
allmirrors->set_long_name("allmirrors");
allmirrors->set_description(_("When running with --url, prints URLs from all available mirrors"));
allmirrors->set_const_value("true");
allmirrors->link_value(allmirrors_option);

urlprotocol_valid_options = {"http", "https", "ftp", "file"};
urlprotocol_option = {};
auto urlprotocol = parser.add_new_named_arg("urlprotocol");
Expand Down Expand Up @@ -152,6 +161,7 @@ void DownloadCommand::set_argument_parser() {
cmd.register_named_arg(srpm);
cmd.register_named_arg(url);
cmd.register_named_arg(urlprotocol);
cmd.register_named_arg(allmirrors);
cmd.register_positional_arg(keys);
}

Expand Down Expand Up @@ -273,7 +283,13 @@ void DownloadCommand::run() {
ctx.get_base().get_logger()->warning("Failed to get mirror for package: \"{}\"", pkg.get_name());
continue;
}
std::cout << urls[0] << std::endl;
std::cout << urls[0];
if (allmirrors_option->get_value()) {
for (size_t index = 1; index < urls.size(); ++index) {
std::cout << " " << urls[index];
}
}
std::cout << std::endl;
}
return;
}
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 @@ -47,6 +47,7 @@ class DownloadCommand : public Command {
libdnf5::OptionBool * resolve_option{nullptr};
libdnf5::OptionBool * alldeps_option{nullptr};
libdnf5::OptionBool * url_option{nullptr};
libdnf5::OptionBool * allmirrors_option{nullptr};
libdnf5::OptionBool * srpm_option{nullptr};

std::vector<std::unique_ptr<libdnf5::Option>> * patterns_to_download_options{nullptr};
Expand Down
3 changes: 3 additions & 0 deletions doc/commands/download.8.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ 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.
``--allmirrors``
| To be used together with ``--url``. It prints out space-separated URLs from all available mirrors for each package.

Examples
========
Expand Down
Loading