2 * Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
3 * Distributed under the terms of the MIT License.
14 #include <package/hpkg/PackageInfoAttributeValue.h>
15 #include <package/hpkg/RepositoryContentHandler.h>
16 #include <package/hpkg/RepositoryReader.h>
17 #include <package/hpkg/StandardErrorOutput.h>
18 #include <package/PackageInfo.h>
19 #include <package/RepositoryInfo.h>
21 #include "package_repo.h"
22 #include "PackageInfoPrinter.h"
25 using namespace BPackageKit::BHPKG
;
26 using namespace BPackageKit
;
28 struct RepositoryContentListHandler
: BRepositoryContentHandler
{
29 RepositoryContentListHandler(bool verbose
)
37 virtual status_t
HandlePackage(const char* packageName
)
42 virtual status_t
HandlePackageAttribute(
43 const BPackageInfoAttributeValue
& value
)
45 if (value
.attributeID
== B_PACKAGE_INFO_NAME
) {
47 printf("package-attributes:\n");
48 fPrinter
.PrintName(value
.string
);
50 printf("\t%s\n", value
.string
);
52 if (fVerbose
&& !fPrinter
.PrintAttribute(value
)) {
53 printf("*** Invalid package attribute section: unexpected "
54 "package attribute id %d encountered\n", value
.attributeID
);
62 virtual status_t
HandlePackageDone(const char* packageName
)
67 virtual status_t
HandleRepositoryInfo(const BRepositoryInfo
& repositoryInfo
)
69 printf("repository-info:\n");
70 printf("\tname: %s\n", repositoryInfo
.Name().String());
71 printf("\tsummary: %s\n", repositoryInfo
.Summary().String());
72 printf("\turl: %s\n", repositoryInfo
.OriginalBaseURL().String());
73 printf("\tvendor: %s\n", repositoryInfo
.Vendor().String());
74 printf("\tpriority: %u\n", repositoryInfo
.Priority());
75 printf("\tarchitecture: %s\n",
76 BPackageInfo::kArchitectureNames
[repositoryInfo
.Architecture()]);
77 const BStringList licenseNames
= repositoryInfo
.LicenseNames();
78 if (!licenseNames
.IsEmpty()) {
79 printf("\tlicenses:\n");
80 for (int i
= 0; i
< licenseNames
.CountStrings(); ++i
)
81 printf("\t\t%s\n", licenseNames
.StringAt(i
).String());
83 printf("packages:\n");
88 virtual void HandleErrorOccurred()
93 static void _PrintPackageVersion(const BPackageVersionData
& version
)
95 printf("%s", BPackageVersion(version
).ToString().String());
99 PackageInfoPrinter fPrinter
;
106 command_list(int argc
, const char* const* argv
)
108 bool verbose
= false;
111 static struct option sLongOptions
[] = {
112 { "help", no_argument
, 0, 'h' },
113 { "verbose", no_argument
, 0, 'v' },
117 opterr
= 0; // don't print errors
118 int c
= getopt_long(argc
, (char**)argv
, "+hv", sLongOptions
, NULL
);
124 print_usage_and_exit(false);
132 print_usage_and_exit(true);
137 // One argument should remain -- the repository file name.
138 if (optind
+ 1 != argc
)
139 print_usage_and_exit(true);
141 const char* repositoryFileName
= argv
[optind
++];
144 BStandardErrorOutput errorOutput
;
145 BRepositoryReader
repositoryReader(&errorOutput
);
146 status_t error
= repositoryReader
.Init(repositoryFileName
);
151 RepositoryContentListHandler
handler(verbose
);
152 error
= repositoryReader
.ParseContent(&handler
);