Skip to content

Commit

Permalink
Respecting the --ns option in zimdump show
Browse files Browse the repository at this point in the history
  • Loading branch information
veloman-yunkan committed Mar 3, 2024
1 parent 6875d84 commit 5d0ff3d
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions src/zimdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class ZimDumper
int listEntriesByNamespace(const std::string ns, bool details);

zim::Entry getEntryByPath(const std::string &path);
zim::Entry getEntryByNsAndPath(char ns, const std::string &path);
zim::Entry getEntry(zim::size_type idx);

void dumpFiles(const std::string& directory, bool symlinkdump, std::function<bool (const char c)> nsfilter);
Expand All @@ -116,6 +117,11 @@ zim::Entry ZimDumper::getEntryByPath(const std::string& path)
return m_archive.getEntryByPath(path);
}

zim::Entry ZimDumper::getEntryByNsAndPath(char ns, const std::string &path)

Check warning on line 120 in src/zimdump.cpp

View check run for this annotation

Codecov / codecov/patch

src/zimdump.cpp#L120

Added line #L120 was not covered by tests
{
return m_archive.getEntryByPathWithNamespace(ns, path);

Check warning on line 122 in src/zimdump.cpp

View check run for this annotation

Codecov / codecov/patch

src/zimdump.cpp#L122

Added line #L122 was not covered by tests
}

zim::Entry ZimDumper::getEntry(zim::size_type idx)
{
return m_archive.getEntryByPath(idx);
Expand Down Expand Up @@ -380,7 +386,9 @@ Return value:
See DIR/dump_errors.log for the listing of the errors.
)";

int subcmdInfo(ZimDumper &app, std::map<std::string, docopt::value> &args)
typedef std::map<std::string, docopt::value> Options;

int subcmdInfo(ZimDumper &app, Options &args)

Check warning on line 391 in src/zimdump.cpp

View check run for this annotation

Codecov / codecov/patch

src/zimdump.cpp#L391

Added line #L391 was not covered by tests
{
app.printInfo();
return 0;
Expand All @@ -396,7 +404,7 @@ int subcmdDumpAll(ZimDumper &app, const std::string &outdir, bool redirect, std:
return 0;
}

int subcmdDump(ZimDumper &app, std::map<std::string, docopt::value> &args)
int subcmdDump(ZimDumper &app, Options &args)

Check warning on line 407 in src/zimdump.cpp

View check run for this annotation

Codecov / codecov/patch

src/zimdump.cpp#L407

Added line #L407 was not covered by tests
{
bool redirect = args["--redirect"].asBool();

Expand All @@ -419,22 +427,33 @@ int subcmdDump(ZimDumper &app, std::map<std::string, docopt::value> &args)
return subcmdDumpAll(app, directory, redirect, filter);
}

int subcmdShow(ZimDumper &app, std::map<std::string, docopt::value> &args)
zim::Entry getEntry(ZimDumper &app, Options &args)

Check warning on line 430 in src/zimdump.cpp

View check run for this annotation

Codecov / codecov/patch

src/zimdump.cpp#L430

Added line #L430 was not covered by tests
{
if (args["--idx"]) {
return app.getEntry(args["--idx"].asLong());
}

const std::string entryPath = args["--url"].asString();
const auto ns = args["--ns"];
if ( !ns ) {
return app.getEntryByPath(entryPath);
}

return app.getEntryByNsAndPath(ns.asString()[0], entryPath);
}

int subcmdShow(ZimDumper &app, Options &args)

Check warning on line 445 in src/zimdump.cpp

View check run for this annotation

Codecov / codecov/patch

src/zimdump.cpp#L445

Added line #L445 was not covered by tests
{
// docopt guaranty us that we have `--idx` or `--url`.
try {
if (args["--idx"]) {
return app.dumpEntry(app.getEntry(args["--idx"].asLong()));
} else {
return app.dumpEntry(app.getEntryByPath(args["--url"].asString()));
}
return app.dumpEntry(getEntry(app, args));
} catch(...) {
std::cerr << "Entry not found" << std::endl;
return -1;
}
}

int subcmdList(ZimDumper &app, std::map<std::string, docopt::value> &args)
int subcmdList(ZimDumper &app, Options &args)

Check warning on line 456 in src/zimdump.cpp

View check run for this annotation

Codecov / codecov/patch

src/zimdump.cpp#L456

Added line #L456 was not covered by tests
{
bool idx(args["--idx"]);
bool url(args["--url"]);
Expand Down Expand Up @@ -465,8 +484,7 @@ int main(int argc, char* argv[])
int ret = 0;
std::ostringstream versions;
printVersions(versions);
std::map<std::string, docopt::value> args
= docopt::docopt(USAGE,
Options args = docopt::docopt(USAGE,
{ argv + 1, argv + argc },
true,
versions.str());
Expand Down

0 comments on commit 5d0ff3d

Please sign in to comment.