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

Bash completion: Always offer NEVRAs and NAMEs for packages #1983

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
2 changes: 1 addition & 1 deletion dnf5/commands/reinstall/reinstall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void ReinstallCommand::set_argument_parser() {
}
return true;
});
keys->set_complete_hook_func([&ctx](const char * arg) { return match_specs(ctx, arg, true, false, true, true); });
keys->set_complete_hook_func([&ctx](const char * arg) { return match_specs(ctx, arg, true, false, true, false); });
cmd.register_positional_arg(keys);

allow_erasing = std::make_unique<AllowErasingOption>(*this);
Expand Down
2 changes: 1 addition & 1 deletion dnf5/commands/remove/remove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void RemoveCommand::set_argument_parser() {
}
return true;
});
keys->set_complete_hook_func([&ctx](const char * arg) { return match_specs(ctx, arg, true, false, false, true); });
keys->set_complete_hook_func([&ctx](const char * arg) { return match_specs(ctx, arg, true, false, false, false); });
cmd.register_positional_arg(keys);

create_offline_option(*this);
Expand Down
2 changes: 1 addition & 1 deletion dnf5/commands/repoquery/repoquery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void RepoqueryCommand::set_argument_parser() {
});
keys->set_complete_hook_func([this, &ctx](const char * arg) {
if (this->installed_option->get_value()) {
return match_specs(ctx, arg, true, false, false, true);
return match_specs(ctx, arg, true, false, false, false);
} else {
return match_specs(ctx, arg, false, true, true, false);
}
Expand Down
2 changes: 1 addition & 1 deletion dnf5/commands/swap/swap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void SwapCommand::set_argument_parser() {
return true;
});
remove_spec_arg->set_complete_hook_func(
[&ctx](const char * arg) { return match_specs(ctx, arg, true, false, false, true); });
[&ctx](const char * arg) { return match_specs(ctx, arg, true, false, false, false); });
cmd.register_positional_arg(remove_spec_arg);

auto install_spec_arg = parser.add_new_positional_arg("install_spec", 1, nullptr, nullptr);
Expand Down
20 changes: 8 additions & 12 deletions dnf5/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ std::vector<std::string> match_specs(
bool installed,
bool available,
bool paths,
bool nevra_for_same_name,
bool only_nevras,
const char * file_name_regex) {
auto & base = ctx.get_base();

Expand Down Expand Up @@ -1128,19 +1128,15 @@ std::vector<std::string> match_specs(
matched_pkgs_query.resolve_pkg_spec(pattern + '*', settings, true);

for (const auto & package : matched_pkgs_query) {
auto [it, inserted] = result_set.insert(package.get_name());

// Package name was already present - not inserted. There are multiple packages with the same name.
// If requested, removes the name and inserts a full nevra for these packages.
if (nevra_for_same_name && !inserted) {
result_set.erase(it);
libdnf5::rpm::PackageQuery name_query(matched_pkgs_query);
name_query.filter_name({package.get_name()});
for (const auto & pkg : name_query) {
result_set.insert(pkg.get_full_nevra());
matched_pkgs_query.remove(pkg);
if (!only_nevras) {
if (auto name = package.get_name(); name.length() >= pattern.length()) {
// The output must not include a package name shorter than the length of the input patter
// (we don't want to shorten the user-specified input).
result_set.insert(std::move(name));
}
}

result_set.insert(package.get_full_nevra());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to skip the source rpm packages NEVRAS?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to skip the source rpm packages NEVRAS?

Now, all matching packages from all allowed repositories are offered. Including source packages.
Fedora source packages are in their own repository, which is disabled by default. If the source package repository is enabled, source packages are offered.

Examples:

# dnf5 download iftop<TAB><TAB>
iftop                              iftop-0:1.0-0.34.pre4.fc41.x86_64  
# dnf5 --enable-repo=fedora-source download iftop<TAB><TAB>
iftop                              iftop-0:1.0-0.34.pre4.fc41.src     iftop-0:1.0-0.34.pre4.fc41.x86_64  

What is meant by the question? Do you want the source packages to not be offered? It is true that NEVRAs for source packages only make sense for certain commands - for example, download.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I discovered it i copr repository, which contains both binary and source rpm. I was just thinking whether *.src packages are usable for the user. But it's really niche issue, as you said - most of the repositories do not contain source packages.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine that .src.rpms are suggested too, the user probably knows what they're doing if they select a specific NEVRA to install/remove/download.

}
}

Expand Down
7 changes: 4 additions & 3 deletions dnf5/include/dnf5/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,9 @@ class DNF_API RpmTransCB : public libdnf5::rpm::TransactionCallbacks {

DNF_API void run_transaction(libdnf5::rpm::Transaction & transaction);

/// Returns the names of matching packages and paths of matching package file names and directories.
/// If `nevra_for_same_name` is true, it returns a full nevra for packages with the same name.
/// Returns the names and nevras of the matching packages and
/// the paths to the matching package file names and directories.
/// The names of the matching packages are returned only if `only_nevras` is false.
/// Only files whose names match `file_name_regex` are returned.
/// NOTE: This function is intended to be used only for autocompletion purposes as the argument parser's
/// complete hook argument. It does the base setup and repos loading inside.
Expand All @@ -296,7 +297,7 @@ DNF_API std::vector<std::string> match_specs(
bool installed,
bool available,
bool paths,
bool nevra_for_same_name,
bool only_nevras,
const char * file_name_regex = ".*\\.rpm");

} // namespace dnf5
Expand Down
Loading