2 * Copyright 2011, Oliver Tappe <zooey@hirschkaefere.de>
3 * Distributed under the terms of the MIT License.
15 #include <ObjectList.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>
28 // TODO: internationalization!
31 using namespace BPackageKit
;
34 static const char* const kShortUsage
=
36 " Lists all repositories.\n";
38 static const char* const kLongUsage
=
40 " %program% %command% [options]\n"
41 "Lists all configured package repositories.\n"
45 DEFINE_COMMAND(ListReposCommand
, "list-repos", kShortUsage
, kLongUsage
,
46 kCommandCategoryRepositories
)
50 ListReposCommand::Execute(int argc
, const char* const* argv
)
55 static struct option sLongOptions
[] = {
56 { "help", no_argument
, 0, 'h' },
57 { "verbose", no_argument
, 0, 'v' },
61 opterr
= 0; // don't print errors
62 int c
= getopt_long(argc
, (char**)argv
, "hv", sLongOptions
, NULL
);
68 PrintUsageAndExit(false);
76 PrintUsageAndExit(true);
81 // No remaining arguments.
83 PrintUsageAndExit(true);
85 BStringList
repositoryNames(20);
86 BPackageRoster roster
;
87 status_t result
= roster
.GetRepositoryNames(repositoryNames
);
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
);
97 repoConfig
.Entry().GetPath(&path
);
98 WARN(result
, "skipping repository-config '%s'", path
.Path());
101 if (verbose
&& i
> 0)
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());
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());
125 printf("\t\t<no repository cache found>\n");