Skip to content

Commit

Permalink
Fixes openzim#171 Adding listEntriesByNamespace
Browse files Browse the repository at this point in the history
  • Loading branch information
maneeshpm committed Jan 28, 2021
1 parent e826b26 commit 9538b46
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/zimdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class ZimDumper
int listEntries(bool info);
int listEntry(const zim::Entry& entry);
void listEntryT(const zim::Entry& entr);
int listEntriesByNamespace(const std::string ns, bool details);

zim::Entry getEntryByPath(const std::string &path);
zim::Entry getEntry(zim::size_type idx);
Expand Down Expand Up @@ -231,6 +232,20 @@ void ZimDumper::listEntryT(const zim::Entry& entry)
}
std::cout << std::endl;
}

int ZimDumper::listEntriesByNamespace(const std::string ns, bool details)
{
int ret = 0;
for (auto& entry:m_archive.findByPath(ns)) {
if (details) {
ret = listEntry(entry);
} else {
std::cout << entry.getPath() << '\n';
}
}
return ret;
}

void write_to_error_directory(const std::string& base, const std::string relpath, const char *content, ssize_t size)
{
createdir(ERRORSDIR, base);
Expand Down Expand Up @@ -447,6 +462,7 @@ int subcmdList(ZimDumper &app, std::map<std::string, docopt::value> &args)
bool idx(args["--idx"]);
bool url(args["--url"]);
bool details = args["--details"].asBool();
bool ns(args["--ns"]);

if (idx || url) {
try {
Expand All @@ -460,8 +476,9 @@ int subcmdList(ZimDumper &app, std::map<std::string, docopt::value> &args)
std::cerr << "Entry not found" << std::endl;
return -1;
}
}
else {
} else if (ns){
return app.listEntriesByNamespace(args["--ns"].asString(), details);
} else {
return app.listEntries(details);
}
}
Expand Down

0 comments on commit 9538b46

Please sign in to comment.