RemoteDrawingEngine: Reduce RP_READ_BITMAP result timeout.
[haiku.git] / src / bin / pkgman / command_uninstall.cpp
blob1d33668a0067362d000ca6a77370b319f5856e25
1 /*
2 * Copyright 2013, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Ingo Weinhold <ingo_weinhold@gmx.de>
7 */
10 #include <getopt.h>
11 #include <stdio.h>
12 #include <stdlib.h>
14 #include "Command.h"
15 #include "pkgman.h"
16 #include "PackageManager.h"
19 // TODO: internationalization!
22 using namespace BPackageKit;
23 using namespace BPackageKit::BPrivate;
26 static const char* const kShortUsage =
27 " %command% <package> ...\n"
28 " Uninstalls one or more packages.\n";
30 static const char* const kLongUsage =
31 "Usage: %program% %command% <package> ...\n"
32 "Uninstalls the specified packages.\n"
33 "\n"
34 "Options:\n"
35 " --debug <level>\n"
36 " Print debug output. <level> should be between 0 (no debug output,\n"
37 " the default) and 10 (most debug output).\n"
38 " -H, --home\n"
39 " Uninstall the packages from the user's home directory. Default is to\n"
40 " uninstall from the system directory.\n"
41 " -y\n"
42 " Non-interactive mode. Automatically confirm changes, but fail when\n"
43 " encountering problems.\n"
44 "\n";
47 DEFINE_COMMAND(UninstallCommand, "uninstall", kShortUsage, kLongUsage,
48 kCommandCategoryPackages)
51 int
52 UninstallCommand::Execute(int argc, const char* const* argv)
54 BPackageInstallationLocation location
55 = B_PACKAGE_INSTALLATION_LOCATION_SYSTEM;
56 bool interactive = true;
58 while (true) {
59 static struct option sLongOptions[] = {
60 { "debug", required_argument, 0, OPTION_DEBUG },
61 { "help", no_argument, 0, 'h' },
62 { "home", no_argument, 0, 'H' },
63 { 0, 0, 0, 0 }
66 opterr = 0; // don't print errors
67 int c = getopt_long(argc, (char**)argv, "hHy", sLongOptions, NULL);
68 if (c == -1)
69 break;
71 if (fCommonOptions.HandleOption(c))
72 continue;
74 switch (c) {
75 case 'h':
76 PrintUsageAndExit(false);
77 break;
79 case 'H':
80 location = B_PACKAGE_INSTALLATION_LOCATION_HOME;
81 break;
83 case 'y':
84 interactive = false;
85 break;
87 default:
88 PrintUsageAndExit(true);
89 break;
93 // The remaining arguments are the packages to be uninstalled.
94 if (argc < optind + 1)
95 PrintUsageAndExit(true);
97 int packageCount = argc - optind;
98 const char* const* packages = argv + optind;
100 // perform the installation
101 PackageManager packageManager(location, interactive);
102 packageManager.SetDebugLevel(fCommonOptions.DebugLevel());
103 packageManager.Uninstall(packages, packageCount);
105 return 0;