package list: Add option "-p"
It prints just a list of paths for all entries.
This commit is contained in:
@@ -274,10 +274,52 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct PackageContentListPathsHandler : BPackageContentHandler {
|
||||||
|
PackageContentListPathsHandler()
|
||||||
|
:
|
||||||
|
fPathComponents()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual status_t HandleEntry(BPackageEntry* entry)
|
||||||
|
{
|
||||||
|
fPathComponents.Add(entry->Name());
|
||||||
|
printf("%s\n", fPathComponents.Join("/").String());
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual status_t HandleEntryAttribute(BPackageEntry* entry,
|
||||||
|
BPackageEntryAttribute* attribute)
|
||||||
|
{
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual status_t HandleEntryDone(BPackageEntry* entry)
|
||||||
|
{
|
||||||
|
fPathComponents.Remove(fPathComponents.CountStrings() - 1);
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual status_t HandlePackageAttribute(
|
||||||
|
const BPackageInfoAttributeValue& value)
|
||||||
|
{
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void HandleErrorOccurred()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
BStringList fPathComponents;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
command_list(int argc, const char* const* argv)
|
command_list(int argc, const char* const* argv)
|
||||||
{
|
{
|
||||||
bool listAttributes = false;
|
bool listAttributes = false;
|
||||||
|
bool filePathsOnly = false;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
static struct option sLongOptions[] = {
|
static struct option sLongOptions[] = {
|
||||||
@@ -286,7 +328,7 @@ command_list(int argc, const char* const* argv)
|
|||||||
};
|
};
|
||||||
|
|
||||||
opterr = 0; // don't print errors
|
opterr = 0; // don't print errors
|
||||||
int c = getopt_long(argc, (char**)argv, "+ha", sLongOptions, NULL);
|
int c = getopt_long(argc, (char**)argv, "+hap", sLongOptions, NULL);
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -299,6 +341,10 @@ command_list(int argc, const char* const* argv)
|
|||||||
print_usage_and_exit(false);
|
print_usage_and_exit(false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'p':
|
||||||
|
filePathsOnly = true;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
print_usage_and_exit(true);
|
print_usage_and_exit(true);
|
||||||
break;
|
break;
|
||||||
@@ -319,8 +365,13 @@ command_list(int argc, const char* const* argv)
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
// list
|
// list
|
||||||
PackageContentListHandler handler(listAttributes);
|
if (filePathsOnly) {
|
||||||
error = packageReader.ParseContent(&handler);
|
PackageContentListPathsHandler handler;
|
||||||
|
error = packageReader.ParseContent(&handler);
|
||||||
|
} else {
|
||||||
|
PackageContentListHandler handler(listAttributes);
|
||||||
|
error = packageReader.ParseContent(&handler);
|
||||||
|
}
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ static const char* kUsage =
|
|||||||
" Lists the contents of package file <package>.\n"
|
" Lists the contents of package file <package>.\n"
|
||||||
"\n"
|
"\n"
|
||||||
" -a - Also list the file attributes.\n"
|
" -a - Also list the file attributes.\n"
|
||||||
|
" -p - Only print a list of file paths.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Common Options:\n"
|
"Common Options:\n"
|
||||||
" -h, --help - Print this usage info.\n"
|
" -h, --help - Print this usage info.\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user