2 * Copyright 2013, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Ingo Weinhold <ingo_weinhold@gmx.de>
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"
36 " Print debug output. <level> should be between 0 (no debug output,\n"
37 " the default) and 10 (most debug output).\n"
39 " Uninstall the packages from the user's home directory. Default is to\n"
40 " uninstall from the system directory.\n"
42 " Non-interactive mode. Automatically confirm changes, but fail when\n"
43 " encountering problems.\n"
47 DEFINE_COMMAND(UninstallCommand
, "uninstall", kShortUsage
, kLongUsage
,
48 kCommandCategoryPackages
)
52 UninstallCommand::Execute(int argc
, const char* const* argv
)
54 BPackageInstallationLocation location
55 = B_PACKAGE_INSTALLATION_LOCATION_SYSTEM
;
56 bool interactive
= 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' },
66 opterr
= 0; // don't print errors
67 int c
= getopt_long(argc
, (char**)argv
, "hHy", sLongOptions
, NULL
);
71 if (fCommonOptions
.HandleOption(c
))
76 PrintUsageAndExit(false);
80 location
= B_PACKAGE_INSTALLATION_LOCATION_HOME
;
88 PrintUsageAndExit(true);
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
);