RemoteDrawingEngine: Reduce RP_READ_BITMAP result timeout.
[haiku.git] / src / bin / pkgman / command_update.cpp
bloba58a40eea89ffc21c6b36c17846f53d8666ed27b
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 " Updates the specified or all packages.\n";
30 static const char* const kLongUsage =
31 "Usage: %program% %command% [ <package> ... ]\n"
32 "Updates the specified packages. If no packages are given, all packages\n"
33 "in the installation location are updated.\n"
34 "A <package> argument can be a search string by which the package is\n"
35 "looked up locally and in a remote repository or a path to a local\n"
36 "package file. In the latter case the file is copied.\n"
37 "\n"
38 "Options:\n"
39 " --debug <level>\n"
40 " Print debug output. <level> should be between 0 (no debug output,\n"
41 " the default) and 10 (most debug output).\n"
42 " -H, --home\n"
43 " Update the packages in the user's home directory. Default is to\n"
44 " update in the system directory.\n"
45 " -y\n"
46 " Non-interactive mode. Automatically confirm changes, but fail when\n"
47 " encountering problems.\n"
48 "\n";
51 DEFINE_COMMAND(UpdateCommand, "update", kShortUsage, kLongUsage,
52 kCommandCategoryPackages)
55 int
56 UpdateCommand::Execute(int argc, const char* const* argv)
58 BPackageInstallationLocation location
59 = B_PACKAGE_INSTALLATION_LOCATION_SYSTEM;
60 bool interactive = true;
62 while (true) {
63 static struct option sLongOptions[] = {
64 { "debug", required_argument, 0, OPTION_DEBUG },
65 { "help", no_argument, 0, 'h' },
66 { "home", no_argument, 0, 'H' },
67 { 0, 0, 0, 0 }
70 opterr = 0; // don't print errors
71 int c = getopt_long(argc, (char**)argv, "hHy", sLongOptions, NULL);
72 if (c == -1)
73 break;
75 if (fCommonOptions.HandleOption(c))
76 continue;
78 switch (c) {
79 case 'h':
80 PrintUsageAndExit(false);
81 break;
83 case 'H':
84 location = B_PACKAGE_INSTALLATION_LOCATION_HOME;
85 break;
87 case 'y':
88 interactive = false;
89 break;
91 default:
92 PrintUsageAndExit(true);
93 break;
97 // The remaining arguments, if any, are the packages to be installed.
98 int packageCount = argc - optind;
99 const char* const* packages = argv + optind;
101 // perform the update
102 PackageManager packageManager(location, interactive);
103 packageManager.SetDebugLevel(fCommonOptions.DebugLevel());
104 packageManager.Update(packages, packageCount);
106 return 0;