@@ -103,6 +103,7 @@ class ZimDumper
103
103
int listEntriesByNamespace (const std::string ns, bool details);
104
104
105
105
zim::Entry getEntryByPath (const std::string &path);
106
+ zim::Entry getEntryByNsAndPath (char ns, const std::string &path);
106
107
zim::Entry getEntry (zim::size_type idx);
107
108
108
109
void dumpFiles (const std::string& directory, bool symlinkdump, std::function<bool (const char c)> nsfilter);
@@ -116,6 +117,11 @@ zim::Entry ZimDumper::getEntryByPath(const std::string& path)
116
117
return m_archive.getEntryByPath (path);
117
118
}
118
119
120
+ zim::Entry ZimDumper::getEntryByNsAndPath (char ns, const std::string &path)
121
+ {
122
+ return m_archive.getEntryByPathWithNamespace (ns, path);
123
+ }
124
+
119
125
zim::Entry ZimDumper::getEntry (zim::size_type idx)
120
126
{
121
127
return m_archive.getEntryByPath (idx);
@@ -380,7 +386,9 @@ Return value:
380
386
See DIR/dump_errors.log for the listing of the errors.
381
387
)" ;
382
388
383
- int subcmdInfo (ZimDumper &app, std::map<std::string, docopt::value> &args)
389
+ typedef std::map<std::string, docopt::value> Options;
390
+
391
+ int subcmdInfo (ZimDumper &app, Options &args)
384
392
{
385
393
app.printInfo ();
386
394
return 0 ;
@@ -396,7 +404,7 @@ int subcmdDumpAll(ZimDumper &app, const std::string &outdir, bool redirect, std:
396
404
return 0 ;
397
405
}
398
406
399
- int subcmdDump (ZimDumper &app, std::map<std::string, docopt::value> &args)
407
+ int subcmdDump (ZimDumper &app, Options &args)
400
408
{
401
409
bool redirect = args[" --redirect" ].asBool ();
402
410
@@ -419,22 +427,33 @@ int subcmdDump(ZimDumper &app, std::map<std::string, docopt::value> &args)
419
427
return subcmdDumpAll (app, directory, redirect, filter);
420
428
}
421
429
422
- int subcmdShow (ZimDumper &app, std::map<std::string, docopt::value> &args)
430
+ zim::Entry getEntry (ZimDumper &app, Options &args)
431
+ {
432
+ if (args[" --idx" ]) {
433
+ return app.getEntry (args[" --idx" ].asLong ());
434
+ }
435
+
436
+ const std::string entryPath = args[" --url" ].asString ();
437
+ const auto ns = args[" --ns" ];
438
+ if ( !ns ) {
439
+ return app.getEntryByPath (entryPath);
440
+ }
441
+
442
+ return app.getEntryByNsAndPath (ns.asString ()[0 ], entryPath);
443
+ }
444
+
445
+ int subcmdShow (ZimDumper &app, Options &args)
423
446
{
424
447
// docopt guaranty us that we have `--idx` or `--url`.
425
448
try {
426
- if (args[" --idx" ]) {
427
- return app.dumpEntry (app.getEntry (args[" --idx" ].asLong ()));
428
- } else {
429
- return app.dumpEntry (app.getEntryByPath (args[" --url" ].asString ()));
430
- }
449
+ return app.dumpEntry (getEntry (app, args));
431
450
} catch (...) {
432
451
std::cerr << " Entry not found" << std::endl;
433
452
return -1 ;
434
453
}
435
454
}
436
455
437
- int subcmdList (ZimDumper &app, std::map<std::string, docopt::value> &args)
456
+ int subcmdList (ZimDumper &app, Options &args)
438
457
{
439
458
bool idx (args[" --idx" ]);
440
459
bool url (args[" --url" ]);
@@ -465,8 +484,7 @@ int main(int argc, char* argv[])
465
484
int ret = 0 ;
466
485
std::ostringstream versions;
467
486
printVersions (versions);
468
- std::map<std::string, docopt::value> args
469
- = docopt::docopt (USAGE,
487
+ Options args = docopt::docopt (USAGE,
470
488
{ argv + 1 , argv + argc },
471
489
true ,
472
490
versions.str ());
0 commit comments