Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respecting the --ns option in zimdump show #316

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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 @@
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 @@
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 @@
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 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
Loading