package_repo: Add -f argument to "list" mode to print filenames.
This way, users of package_repo don't have to reassemble the canonical filenames themselves.
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
#include <package/hpkg/RepositoryReader.h>
|
#include <package/hpkg/RepositoryReader.h>
|
||||||
#include <package/hpkg/StandardErrorOutput.h>
|
#include <package/hpkg/StandardErrorOutput.h>
|
||||||
#include <package/PackageInfo.h>
|
#include <package/PackageInfo.h>
|
||||||
|
#include <package/PackageInfoContentHandler.h>
|
||||||
#include <package/RepositoryInfo.h>
|
#include <package/RepositoryInfo.h>
|
||||||
|
|
||||||
#include "package_repo.h"
|
#include "package_repo.h"
|
||||||
@@ -26,11 +27,13 @@ using namespace BPackageKit::BHPKG;
|
|||||||
using namespace BPackageKit;
|
using namespace BPackageKit;
|
||||||
|
|
||||||
struct RepositoryContentListHandler : BRepositoryContentHandler {
|
struct RepositoryContentListHandler : BRepositoryContentHandler {
|
||||||
RepositoryContentListHandler(bool verbose)
|
RepositoryContentListHandler(bool filenames, bool verbose)
|
||||||
:
|
:
|
||||||
fPrinter(),
|
fPrinter(),
|
||||||
fLevel(0),
|
fLevel(0),
|
||||||
fVerbose(verbose)
|
fVerbose(verbose),
|
||||||
|
fFilenames(filenames),
|
||||||
|
fPackageInfoContentHandler(fPackageInfo, NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,12 +45,16 @@ struct RepositoryContentListHandler : BRepositoryContentHandler {
|
|||||||
virtual status_t HandlePackageAttribute(
|
virtual status_t HandlePackageAttribute(
|
||||||
const BPackageInfoAttributeValue& value)
|
const BPackageInfoAttributeValue& value)
|
||||||
{
|
{
|
||||||
|
if (fFilenames)
|
||||||
|
fPackageInfoContentHandler.HandlePackageAttribute(value);
|
||||||
|
|
||||||
if (value.attributeID == B_PACKAGE_INFO_NAME) {
|
if (value.attributeID == B_PACKAGE_INFO_NAME) {
|
||||||
if (fVerbose) {
|
if (fVerbose) {
|
||||||
printf("package-attributes:\n");
|
printf("package-attributes:\n");
|
||||||
fPrinter.PrintName(value.string);
|
fPrinter.PrintName(value.string);
|
||||||
} else
|
} else if (!fFilenames) {
|
||||||
printf("\t%s\n", value.string);
|
printf("\t%s\n", value.string);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (fVerbose && !fPrinter.PrintAttribute(value)) {
|
if (fVerbose && !fPrinter.PrintAttribute(value)) {
|
||||||
printf("*** Invalid package attribute section: unexpected "
|
printf("*** Invalid package attribute section: unexpected "
|
||||||
@@ -61,6 +68,11 @@ struct RepositoryContentListHandler : BRepositoryContentHandler {
|
|||||||
|
|
||||||
virtual status_t HandlePackageDone(const char* packageName)
|
virtual status_t HandlePackageDone(const char* packageName)
|
||||||
{
|
{
|
||||||
|
if (fFilenames) {
|
||||||
|
printf("%s%s\n", fVerbose ? "filename: " : "\t",
|
||||||
|
fPackageInfo.CanonicalFileName().String());
|
||||||
|
fPackageInfo.Clear();
|
||||||
|
}
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,23 +112,28 @@ private:
|
|||||||
PackageInfoPrinter fPrinter;
|
PackageInfoPrinter fPrinter;
|
||||||
int fLevel;
|
int fLevel;
|
||||||
bool fVerbose;
|
bool fVerbose;
|
||||||
|
|
||||||
|
bool fFilenames;
|
||||||
|
BPackageInfoContentHandler fPackageInfoContentHandler;
|
||||||
|
BPackageInfo fPackageInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
command_list(int argc, const char* const* argv)
|
command_list(int argc, const char* const* argv)
|
||||||
{
|
{
|
||||||
bool verbose = false;
|
bool verbose = false, filenames = false;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
static struct option sLongOptions[] = {
|
static struct option sLongOptions[] = {
|
||||||
{ "help", no_argument, 0, 'h' },
|
{ "help", no_argument, 0, 'h' },
|
||||||
|
{ "filenames", no_argument, 0, 'f' },
|
||||||
{ "verbose", no_argument, 0, 'v' },
|
{ "verbose", no_argument, 0, 'v' },
|
||||||
{ 0, 0, 0, 0 }
|
{ 0, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
opterr = 0; // don't print errors
|
opterr = 0; // don't print errors
|
||||||
int c = getopt_long(argc, (char**)argv, "+hv", sLongOptions, NULL);
|
int c = getopt_long(argc, (char**)argv, "+hfv", sLongOptions, NULL);
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -125,6 +142,10 @@ command_list(int argc, const char* const* argv)
|
|||||||
print_usage_and_exit(false);
|
print_usage_and_exit(false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'f':
|
||||||
|
filenames = true;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
verbose = true;
|
verbose = true;
|
||||||
break;
|
break;
|
||||||
@@ -149,7 +170,7 @@ command_list(int argc, const char* const* argv)
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
// list
|
// list
|
||||||
RepositoryContentListHandler handler(verbose);
|
RepositoryContentListHandler handler(filenames, verbose);
|
||||||
error = repositoryReader.ParseContent(&handler);
|
error = repositoryReader.ParseContent(&handler);
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ static const char* kUsage =
|
|||||||
" list [ <options> ] <package-repo>\n"
|
" list [ <options> ] <package-repo>\n"
|
||||||
" Lists the contents of package repository file <package-repo>.\n"
|
" Lists the contents of package repository file <package-repo>.\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
" -f - print canonical filenames of packages.\n"
|
||||||
" -v - be verbose (list attributes of all packages found).\n"
|
" -v - be verbose (list attributes of all packages found).\n"
|
||||||
"\n"
|
"\n"
|
||||||
" update [ <options> ] <source-repo> <new-repo> <package-list-file> \n"
|
" update [ <options> ] <source-repo> <new-repo> <package-list-file> \n"
|
||||||
|
|||||||
Reference in New Issue
Block a user