RemoteDrawingEngine: Reduce RP_READ_BITMAP result timeout.
[haiku.git] / src / bin / pkgman / command_install.cpp
blobe26207bb3e240b657afd9340e994f0aefca6a319
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 " Installs one or more packages.\n";
30 static const char* const kLongUsage =
31 "Usage: %program% %command% <package> ...\n"
32 "Installs the specified packages. A <package> argument can be a search\n"
33 "string by which the package is looked up in a remote repository or a\n"
34 "path to a local package file. In the latter case the file is copied.\n"
35 "\n"
36 "Options:\n"
37 " --debug <level>\n"
38 " Print debug output. <level> should be between 0 (no debug output,\n"
39 " the default) and 10 (most debug output).\n"
40 " -H, --home\n"
41 " Install the packages in the user's home directory. Default is to\n"
42 " install in the system directory.\n"
43 " -y\n"
44 " Non-interactive mode. Automatically confirm changes, but fail when\n"
45 " encountering problems.\n"
46 "\n";
49 DEFINE_COMMAND(InstallCommand, "install", kShortUsage, kLongUsage,
50 kCommandCategoryPackages)
53 int
54 InstallCommand::Execute(int argc, const char* const* argv)
56 BPackageInstallationLocation location
57 = B_PACKAGE_INSTALLATION_LOCATION_SYSTEM;
58 bool interactive = true;
60 while (true) {
61 static struct option sLongOptions[] = {
62 { "debug", required_argument, 0, OPTION_DEBUG },
63 { "help", no_argument, 0, 'h' },
64 { "home", no_argument, 0, 'H' },
65 { 0, 0, 0, 0 }
68 opterr = 0; // don't print errors
69 int c = getopt_long(argc, (char**)argv, "hHy", sLongOptions, NULL);
70 if (c == -1)
71 break;
73 if (fCommonOptions.HandleOption(c))
74 continue;
76 switch (c) {
77 case 'h':
78 PrintUsageAndExit(false);
79 break;
81 case 'H':
82 location = B_PACKAGE_INSTALLATION_LOCATION_HOME;
83 break;
85 case 'y':
86 interactive = false;
87 break;
89 default:
90 PrintUsageAndExit(true);
91 break;
95 // The remaining arguments are the packages to be installed.
96 if (argc < optind + 1)
97 PrintUsageAndExit(true);
99 int packageCount = argc - optind;
100 const char* const* packages = argv + optind;
102 // perform the installation
103 PackageManager packageManager(location, interactive);
104 packageManager.SetDebugLevel(fCommonOptions.DebugLevel());
105 packageManager.Install(packages, packageCount);
107 return 0;