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 " 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"
38 " Print debug output. <level> should be between 0 (no debug output,\n"
39 " the default) and 10 (most debug output).\n"
41 " Install the packages in the user's home directory. Default is to\n"
42 " install in the system directory.\n"
44 " Non-interactive mode. Automatically confirm changes, but fail when\n"
45 " encountering problems.\n"
49 DEFINE_COMMAND(InstallCommand
, "install", kShortUsage
, kLongUsage
,
50 kCommandCategoryPackages
)
54 InstallCommand::Execute(int argc
, const char* const* argv
)
56 BPackageInstallationLocation location
57 = B_PACKAGE_INSTALLATION_LOCATION_SYSTEM
;
58 bool interactive
= 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' },
68 opterr
= 0; // don't print errors
69 int c
= getopt_long(argc
, (char**)argv
, "hHy", sLongOptions
, NULL
);
73 if (fCommonOptions
.HandleOption(c
))
78 PrintUsageAndExit(false);
82 location
= B_PACKAGE_INSTALLATION_LOCATION_HOME
;
90 PrintUsageAndExit(true);
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
);