pkgman: change default search scope

* Reduce default search scope to: "name", "summary", and "provides".
* Add a new "--search-scope=<scope>" option that allows to either limit
  the search to packages names (-s name), or to replicate the previous
  behavior of searching everywhere in the package info (-s full).

Motivation for the change:

The ever increasing number of packages available for Haiku was impacting
pkgman search usefulness, as it easily returns too many packages (what a
wonderful problem to have :-D).

Limiting the default search scope helps with that, and the old behavior
is kept "just an option away".

Change-Id: I5b456b90137237134eee7ca7ee501bf8e3767440
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5616
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
This commit is contained in:
Oscar Lesta 2022-09-04 11:47:48 +00:00 committed by waddlesplash
parent e4d44d82aa
commit 8fc394c12d

View File

@ -55,6 +55,9 @@ static const char* const kLongUsage =
" Only find not installed packages.\n" " Only find not installed packages.\n"
" -r, --requirements\n" " -r, --requirements\n"
" Search packages with <search-string> as requirements.\n" " Search packages with <search-string> as requirements.\n"
" -s <scope>, --search-scope=<scope>\n"
" Search for packages containing <search-string> only on the given scope.\n"
" <scope> must be either \"name\" or \"full\"."
"\n" "\n"
"Status flags in non-detailed listings:\n" "Status flags in non-detailed listings:\n"
" S - installed in system with a matching version in a repository\n" " S - installed in system with a matching version in a repository\n"
@ -132,6 +135,8 @@ SearchCommand::Execute(int argc, const char* const* argv)
{ {
bool installedOnly = false; bool installedOnly = false;
bool uninstalledOnly = false; bool uninstalledOnly = false;
bool nameOnly = false;
bool fullSearch = false;
bool listAll = false; bool listAll = false;
bool details = false; bool details = false;
bool requirements = false; bool requirements = false;
@ -145,11 +150,12 @@ SearchCommand::Execute(int argc, const char* const* argv)
{ "installed-only", no_argument, 0, 'i' }, { "installed-only", no_argument, 0, 'i' },
{ "uninstalled-only", no_argument, 0, 'u' }, { "uninstalled-only", no_argument, 0, 'u' },
{ "requirements", no_argument, 0, 'r' }, { "requirements", no_argument, 0, 'r' },
{ "search-scope", required_argument, NULL, 's' },
{ 0, 0, 0, 0 } { 0, 0, 0, 0 }
}; };
opterr = 0; // don't print errors opterr = 0; // don't print errors
int c = getopt_long(argc, (char**)argv, "aDhiur", sLongOptions, NULL); int c = getopt_long(argc, (char**)argv, "aDhiurs:", sLongOptions, NULL);
if (c == -1) if (c == -1)
break; break;
@ -183,6 +189,16 @@ SearchCommand::Execute(int argc, const char* const* argv)
requirements = true; requirements = true;
break; break;
case 's':
if (strcmp(optarg, "name") == 0)
nameOnly = true;
else if (strcmp(optarg, "full") == 0)
fullSearch = true;
else
fprintf(stderr, "Warning: Invalid search scope (%s). Using default.\n",
optarg);
break;
default: default:
PrintUsageAndExit(true); PrintUsageAndExit(true);
break; break;
@ -204,10 +220,19 @@ SearchCommand::Execute(int argc, const char* const* argv)
| (!installedOnly ? PackageManager::B_ADD_REMOTE_REPOSITORIES : 0)); | (!installedOnly ? PackageManager::B_ADD_REMOTE_REPOSITORIES : 0));
uint32 flags = BSolver::B_FIND_CASE_INSENSITIVE | BSolver::B_FIND_IN_NAME uint32 flags = BSolver::B_FIND_CASE_INSENSITIVE | BSolver::B_FIND_IN_NAME
| BSolver::B_FIND_IN_SUMMARY | BSolver::B_FIND_IN_DESCRIPTION | BSolver::B_FIND_IN_SUMMARY | BSolver::B_FIND_IN_PROVIDES;
| BSolver::B_FIND_IN_PROVIDES;
if (nameOnly)
flags = BSolver::B_FIND_CASE_INSENSITIVE | BSolver::B_FIND_IN_NAME;
if (fullSearch)
flags = BSolver::B_FIND_CASE_INSENSITIVE | BSolver::B_FIND_IN_NAME
| BSolver::B_FIND_IN_SUMMARY | BSolver::B_FIND_IN_DESCRIPTION
| BSolver::B_FIND_IN_PROVIDES;
if (requirements) if (requirements)
flags = BSolver::B_FIND_IN_REQUIRES; flags = BSolver::B_FIND_IN_REQUIRES;
// search // search
BObjectList<BSolverPackage> packages; BObjectList<BSolverPackage> packages;
status_t error = packageManager.Solver()->FindPackages(searchString, status_t error = packageManager.Solver()->FindPackages(searchString,