Skip to content

Commit

Permalink
Add --all-mirros option for dnf download --url
Browse files Browse the repository at this point in the history
  • Loading branch information
alimirjamali committed Sep 30, 2024
1 parent ce289e9 commit 17a0ed3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
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))));

urlallmirrors_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 urlallmirrors = parser.add_new_named_arg("allmirrors");
urlallmirrors->set_long_name("allmirrors");
urlallmirrors->set_description _("When running with --url, prints URLs from all available mirrors");
urlallmirrors->set_const_value("true");
urlallmirrors->link_value(urlallmirrors_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(urlallmirrors);
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 (urlallmirrors_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 * urlallmirrors_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

0 comments on commit 17a0ed3

Please sign in to comment.