Make UEFI boot-platform build again
[haiku.git] / src / bin / pkgman / command_drop_repo.cpp
blob9c4988a8bf8399aed63639cf9e4a6e2962428927
1 /*
2 * Copyright 2011, Oliver Tappe <zooey@hirschkaefere.de>
3 * Distributed under the terms of the MIT License.
4 */
7 #include <getopt.h>
8 #include <stdio.h>
9 #include <stdlib.h>
11 #include <Errors.h>
12 #include <SupportDefs.h>
14 #include <package/DropRepositoryRequest.h>
15 #include <package/Context.h>
17 #include "Command.h"
18 #include "DecisionProvider.h"
19 #include "JobStateListener.h"
20 #include "pkgman.h"
23 using namespace BPackageKit;
26 // TODO: internationalization!
29 static const char* const kShortUsage =
30 " %command% <repo-name>\n"
31 " Drops the repository with the given <repo-name>.\n";
33 static const char* const kLongUsage =
34 "Usage: %program% %command% <repo-name>\n"
35 "Drops (i.e. removes) the repository with the given name.\n"
36 "\n";
39 DEFINE_COMMAND(DropRepoCommand, "drop-repo", kShortUsage, kLongUsage,
40 kCommandCategoryRepositories)
43 int
44 DropRepoCommand::Execute(int argc, const char* const* argv)
46 bool yesMode = false;
48 while (true) {
49 static struct option sLongOptions[] = {
50 { "help", no_argument, 0, 'h' },
51 { "yes", no_argument, 0, 'y' },
52 { 0, 0, 0, 0 }
55 opterr = 0; // don't print errors
56 int c = getopt_long(argc, (char**)argv, "hu", sLongOptions, NULL);
57 if (c == -1)
58 break;
60 switch (c) {
61 case 'h':
62 PrintUsageAndExit(false);
63 break;
65 case 'y':
66 yesMode = true;
67 break;
69 default:
70 PrintUsageAndExit(true);
71 break;
75 // The remaining argument is a repo name, i. e. one more argument.
76 if (argc != optind + 1)
77 PrintUsageAndExit(true);
79 const char* repoName = argv[optind];
81 DecisionProvider decisionProvider;
82 // if (yesMode)
83 // decisionProvider.SetAcceptEverything(true);
84 JobStateListener listener;
85 BContext context(decisionProvider, listener);
87 status_t result;
88 DropRepositoryRequest dropRequest(context, repoName);
89 result = dropRequest.Process(true);
90 if (result != B_OK) {
91 if (result != B_CANCELED) {
92 DIE(result, "request for dropping repository \"%s\" failed",
93 repoName);
95 return 1;
98 return 0;