Skip to content

Commit

Permalink
Support older version of docopt.
Browse files Browse the repository at this point in the history
Older version of docopt doesn't define Options.

Let's define it using `using` syntax (as done in recent version of docoptcpp)
  • Loading branch information
mgautierfr committed Aug 30, 2024
1 parent 73eb7c2 commit a4c4321
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/zimcheck/zimcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ R"(Zimcheck checks the quality of a ZIM file.
zimcheck -m --favicon wikipedia.zim)";


// Older version of docopt doesn't define Options
using Options = std::map<std::string, docopt::value>;

template<class T>
std::string stringify(const T& x)
{
Expand All @@ -97,7 +100,7 @@ int zimcheck(const std::vector<const char*>& args) {
args_string.emplace_back(arg);
}

docopt::Options parsed_args;
Options parsed_args;
try {
parsed_args = docopt::docopt_parse(
USAGE,
Expand All @@ -112,7 +115,7 @@ int zimcheck(const std::vector<const char*>& args) {
return zimcheck(parsed_args);
}

int zimcheck(const docopt::Options& args)
int zimcheck(const Options& args)
{
// To calculate the total time taken by the program to run.
const auto starttime = std::chrono::steady_clock::now();
Expand Down
4 changes: 3 additions & 1 deletion src/zimdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,9 @@ Return value:
See DIR/dump_errors.log for the listing of the errors.
)";

typedef std::map<std::string, docopt::value> Options;

// Older version of docopt doesn't define Options
using Options = std::map<std::string, docopt::value>;

int subcmdInfo(ZimDumper &app, Options &args)
{
Expand Down
8 changes: 4 additions & 4 deletions src/zimsplit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@ int main(int argc, char* argv[])
{
std::ostringstream versions;
printVersions(versions);
std::map<std::string, docopt::value> args = docopt::docopt(USAGE,
{argv + 1, argv + argc},
true,
versions.str());
auto args = docopt::docopt(USAGE,
{argv + 1, argv + argc},

Check warning on line 184 in src/zimsplit.cpp

View check run for this annotation

Codecov / codecov/patch

src/zimsplit.cpp#L184

Added line #L184 was not covered by tests
true,
versions.str());

std::string prefix = args["<file>"].asString();
if (args["--prefix"])
Expand Down

0 comments on commit a4c4321

Please sign in to comment.