From 0214aefd58d6ccca6fb2a7f6c6c7b57f858f422f Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sun, 25 Aug 2013 17:19:14 +0200 Subject: [PATCH] pkgman search: add -a/--all Can be specified instead of a search string. Lists all packages. --- src/bin/pkgman/command_search.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/bin/pkgman/command_search.cpp b/src/bin/pkgman/command_search.cpp index 371987c61f..5be2a10270 100644 --- a/src/bin/pkgman/command_search.cpp +++ b/src/bin/pkgman/command_search.cpp @@ -32,14 +32,16 @@ using namespace BPackageKit; static const char* const kShortUsage = - " %command% \n" + " %command% ( | --all | -a )\n" " Searches for packages matching .\n"; static const char* const kLongUsage = - "Usage: %program% %command% \n" + "Usage: %program% %command% ( | --all | -a )\n" "Searches for packages matching .\n" "\n" "Options:\n" + " -a, --all\n" + " List all packages. Specified instead of .\n" " -i, --installed-only\n" " Only find installed packages.\n" " -u, --uninstalled-only\n" @@ -68,9 +70,11 @@ SearchCommand::Execute(int argc, const char* const* argv) { bool installedOnly = false; bool uninstalledOnly = false; + bool listAll = false; while (true) { static struct option sLongOptions[] = { + { "all", no_argument, 0, 'a' }, { "help", no_argument, 0, 'h' }, { "installed-only", no_argument, 0, 'i' }, { "uninstalled-only", no_argument, 0, 'u' }, @@ -78,11 +82,15 @@ SearchCommand::Execute(int argc, const char* const* argv) }; opterr = 0; // don't print errors - int c = getopt_long(argc, (char**)argv, "hiu", sLongOptions, NULL); + int c = getopt_long(argc, (char**)argv, "ahiu", sLongOptions, NULL); if (c == -1) break; switch (c) { + case 'a': + listAll = true; + break; + case 'h': PrintUsageAndExit(false); break; @@ -103,11 +111,12 @@ SearchCommand::Execute(int argc, const char* const* argv) } } - // The remaining argument is the search string. - if (argc != optind + 1) + // The remaining argument is the search string. Ignored when --all has been + // specified. + if (!listAll && argc != optind + 1) PrintUsageAndExit(true); - const char* searchString = argv[optind++]; + const char* searchString = listAll ? "" : argv[optind++]; // create the solver PackageManager packageManager(B_PACKAGE_INSTALLATION_LOCATION_COMMON,