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 " 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"
40 " Print debug output. <level> should be between 0 (no debug output,\n"
41 " the default) and 10 (most debug output).\n"
43 " Update the packages in the user's home directory. Default is to\n"
44 " update in the system directory.\n"
46 " Non-interactive mode. Automatically confirm changes, but fail when\n"
47 " encountering problems.\n"
51 DEFINE_COMMAND(UpdateCommand
, "update", kShortUsage
, kLongUsage
,
52 kCommandCategoryPackages
)
56 UpdateCommand::Execute(int argc
, const char* const* argv
)
58 BPackageInstallationLocation location
59 = B_PACKAGE_INSTALLATION_LOCATION_SYSTEM
;
60 bool interactive
= 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' },
70 opterr
= 0; // don't print errors
71 int c
= getopt_long(argc
, (char**)argv
, "hHy", sLongOptions
, NULL
);
75 if (fCommonOptions
.HandleOption(c
))
80 PrintUsageAndExit(false);
84 location
= B_PACKAGE_INSTALLATION_LOCATION_HOME
;
92 PrintUsageAndExit(true);
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
);