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 28, 2024
1 parent ce289e9 commit 51755a2
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 @@ -115,6 +118,12 @@ void DownloadCommand::set_argument_parser() {
return true;
});

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

arch_option = {};
auto arch = parser.add_new_named_arg("arch");
arch->set_long_name("arch");
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;
if (urlallmirrors_option->get_value()) {
for (auto &url: urls) {
std::cout << url << std::endl;
}
} else {
std::cout << urls[0] << 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.
``--all-mirrors``
| To be used together with ``--url``. It prints out the URLs from all available mirrors.

Examples
========
Expand Down

0 comments on commit 51755a2

Please sign in to comment.