Make UEFI boot-platform build again
[haiku.git] / src / bin / pkgman / command_list_repos.cpp
blob677983a8f6ab77ee8418c4902140bec492d90d39
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 <new>
13 #include <Entry.h>
14 #include <Errors.h>
15 #include <ObjectList.h>
16 #include <Path.h>
18 #include <package/RepositoryCache.h>
19 #include <package/RepositoryConfig.h>
20 #include <package/PackageInfo.h>
21 #include <package/PackageRoster.h>
22 #include <package/RepositoryInfo.h>
24 #include "Command.h"
25 #include "pkgman.h"
28 // TODO: internationalization!
31 using namespace BPackageKit;
34 static const char* const kShortUsage =
35 " %command%\n"
36 " Lists all repositories.\n";
38 static const char* const kLongUsage =
39 "Usage:\n"
40 " %program% %command% [options]\n"
41 "Lists all configured package repositories.\n"
42 "\n";
45 DEFINE_COMMAND(ListReposCommand, "list-repos", kShortUsage, kLongUsage,
46 kCommandCategoryRepositories)
49 int
50 ListReposCommand::Execute(int argc, const char* const* argv)
52 bool verbose = false;
54 while (true) {
55 static struct option sLongOptions[] = {
56 { "help", no_argument, 0, 'h' },
57 { "verbose", no_argument, 0, 'v' },
58 { 0, 0, 0, 0 }
61 opterr = 0; // don't print errors
62 int c = getopt_long(argc, (char**)argv, "hv", sLongOptions, NULL);
63 if (c == -1)
64 break;
66 switch (c) {
67 case 'h':
68 PrintUsageAndExit(false);
69 break;
71 case 'v':
72 verbose = true;
73 break;
75 default:
76 PrintUsageAndExit(true);
77 break;
81 // No remaining arguments.
82 if (argc != optind)
83 PrintUsageAndExit(true);
85 BStringList repositoryNames(20);
86 BPackageRoster roster;
87 status_t result = roster.GetRepositoryNames(repositoryNames);
88 if (result != B_OK)
89 DIE(result, "can't collect repository names");
91 for (int i = 0; i < repositoryNames.CountStrings(); ++i) {
92 const BString& repoName = repositoryNames.StringAt(i);
93 BRepositoryConfig repoConfig;
94 result = roster.GetRepositoryConfig(repoName, &repoConfig);
95 if (result != B_OK) {
96 BPath path;
97 repoConfig.Entry().GetPath(&path);
98 WARN(result, "skipping repository-config '%s'", path.Path());
99 continue;
101 if (verbose && i > 0)
102 printf("\n");
103 printf(" %s %s\n",
104 repoConfig.IsUserSpecific() ? "[User]" : " ",
105 repoConfig.Name().String());
106 printf("\t\tbase-url: %s\n", repoConfig.BaseURL().String());
107 printf("\t\tpriority: %u\n", repoConfig.Priority());
109 if (verbose) {
110 BRepositoryCache repoCache;
111 result = roster.GetRepositoryCache(repoName, &repoCache);
112 if (result == B_OK) {
113 printf("\t\tvendor: %s\n",
114 repoCache.Info().Vendor().String());
115 printf("\t\tsummary: %s\n",
116 repoCache.Info().Summary().String());
117 printf("\t\tarch: %s\n", BPackageInfo::kArchitectureNames[
118 repoCache.Info().Architecture()]);
119 printf("\t\tpkg-count: %" B_PRIu32 "\n",
120 repoCache.CountPackages());
121 printf("\t\torig-url: %s\n",
122 repoCache.Info().OriginalBaseURL().String());
123 printf("\t\torig-prio: %u\n", repoCache.Info().Priority());
124 } else
125 printf("\t\t<no repository cache found>\n");
129 return 0;