2 * Copyright 2011, Oliver Tappe <zooey@hirschkaefere.de>
3 * Distributed under the terms of the MIT License.
12 #include <SupportDefs.h>
14 #include <package/DropRepositoryRequest.h>
15 #include <package/Context.h>
18 #include "DecisionProvider.h"
19 #include "JobStateListener.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"
39 DEFINE_COMMAND(DropRepoCommand
, "drop-repo", kShortUsage
, kLongUsage
,
40 kCommandCategoryRepositories
)
44 DropRepoCommand::Execute(int argc
, const char* const* argv
)
49 static struct option sLongOptions
[] = {
50 { "help", no_argument
, 0, 'h' },
51 { "yes", no_argument
, 0, 'y' },
55 opterr
= 0; // don't print errors
56 int c
= getopt_long(argc
, (char**)argv
, "hu", sLongOptions
, NULL
);
62 PrintUsageAndExit(false);
70 PrintUsageAndExit(true);
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
;
83 // decisionProvider.SetAcceptEverything(true);
84 JobStateListener listener
;
85 BContext
context(decisionProvider
, listener
);
88 DropRepositoryRequest
dropRequest(context
, repoName
);
89 result
= dropRequest
.Process(true);
91 if (result
!= B_CANCELED
) {
92 DIE(result
, "request for dropping repository \"%s\" failed",