Skip to content

Commit

Permalink
Bash completion: always offer NEVRAs for packages
Browse files Browse the repository at this point in the history
Originally, for packages, the NAME was offered in bash completion.
In the case of multiple packages with the same NAME, there was an option
to offer NEVRA instead of the NAME for those packages.

Now, bash completion always offers NEVRA for packages.
There is an option to offer package NAMEs in addition to NEVRAs. This is
useful, for example, when the user wants to install a package. Usually
the user only wants to enter the package NAME and not the entire NEVRA.
If multiple packages with the same NAME are available, the specific
package is then selected by the solver.
  • Loading branch information
jrohel committed Jan 7, 2025
1 parent 8751434 commit 9bae31a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
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());
}
}

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

0 comments on commit 9bae31a

Please sign in to comment.