pkgman [un]install/update: Add non-interactive mode (-y)

This commit is contained in:
Ingo Weinhold
2013-11-22 13:33:48 +01:00
parent 2b76973fa2
commit 83f63a216e
7 changed files with 80 additions and 14 deletions
+10 -2
View File
@@ -36,6 +36,9 @@ static const char* const kLongUsage =
" -H, --home\n"
" Update the packages in the user's home directory. Default is to\n"
" update in the system directory.\n"
" -y\n"
" Non-interactive mode. Automatically confirm changes, but fail when\n"
" encountering problems.\n"
"\n";
@@ -48,6 +51,7 @@ UpdateCommand::Execute(int argc, const char* const* argv)
{
BPackageInstallationLocation location
= B_PACKAGE_INSTALLATION_LOCATION_SYSTEM;
bool interactive = true;
while (true) {
static struct option sLongOptions[] = {
@@ -57,7 +61,7 @@ UpdateCommand::Execute(int argc, const char* const* argv)
};
opterr = 0; // don't print errors
int c = getopt_long(argc, (char**)argv, "hH", sLongOptions, NULL);
int c = getopt_long(argc, (char**)argv, "hHy", sLongOptions, NULL);
if (c == -1)
break;
@@ -70,6 +74,10 @@ UpdateCommand::Execute(int argc, const char* const* argv)
location = B_PACKAGE_INSTALLATION_LOCATION_HOME;
break;
case 'y':
interactive = false;
break;
default:
PrintUsageAndExit(true);
break;
@@ -81,7 +89,7 @@ UpdateCommand::Execute(int argc, const char* const* argv)
const char* const* packages = argv + optind;
// perform the update
PackageManager packageManager(location);
PackageManager packageManager(location, interactive);
packageManager.Update(packages, packageCount);
return 0;