Skip to content

Commit

Permalink
Merge pull request #275 from openzim/better_version
Browse files Browse the repository at this point in the history
Better version
  • Loading branch information
kelson42 authored Jan 3, 2022
2 parents 4754843 + 6f5c3ba commit a26a450
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 36 deletions.
9 changes: 6 additions & 3 deletions src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@

#include <iostream>

#include <zim/version.h>

#ifndef VERSION
#define VERSION "undefined"
#endif

void version()
{
std::cout << VERSION << std::endl;
void printVersions(std::ostream& out = std::cout) {
out << "zim-tools " << VERSION << std::endl;
out << std::endl;
zim::printVersions(out);
}

#endif //_ZIM_TOOL_VERSION_H_
2 changes: 1 addition & 1 deletion src/zimbench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ int main(int argc, char* argv[])
distinctCount = atoi(optarg);
break;
case 'v':
version();
printVersions();
return 0;
};
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/zimcheck/zimcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ int zimcheck (const std::vector<const char*>& args)
return 1;
case 'V':
case 'v':
version();
printVersions();
return 0;
default:
abort ();
Expand Down
2 changes: 1 addition & 1 deletion src/zimdiff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ int main(int argc, char* argv[])
if(std::string(argv[i])=="--version" ||
std::string(argv[i])=="-v")
{
version();
printVersions();
return 0;
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/zimdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,13 @@ int subcmdList(ZimDumper &app, std::map<std::string, docopt::value> &args)
int main(int argc, char* argv[])
{
int ret = 0;
std::string versionstr("zimdump " + std::string(VERSION));
std::ostringstream versions;
printVersions(versions);
std::map<std::string, docopt::value> args
= docopt::docopt(USAGE,
{ argv + 1, argv + argc },
true,
versionstr);
versions.str());

try {
ZimDumper app(args["<file>"].asString());
Expand Down
2 changes: 1 addition & 1 deletion src/zimpatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ int main(int argc, char* argv[])
if(std::string(argv[i])=="--version" ||
std::string(argv[i])=="-v")
{
version();
printVersions();
return 0;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/zimrecreate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ int main(int argc, char* argv[])
if(std::string(argv[i])=="--version" ||
std::string(argv[i])=="-v")
{
version();
printVersions();
return 0;
}

Expand Down
6 changes: 3 additions & 3 deletions src/zimsearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ int main(int argc, char* argv[])
{

// version number
if (argc > 1 && std::string(argv[1]) == "-v")
if (argc > 1 && (std::string(argv[1]) == "-v" || std::string(argv[1])=="--version"))
{
version();
printVersions();
return 0;
}

Expand All @@ -51,7 +51,7 @@ int main(int argc, char* argv[])
"\n"
"options\n"
" -x indexfile specify indexfile\n"
" -v print software version\n" << std::endl;
" -v, --version print software version\n" << std::endl;
return 1;
}

Expand Down
11 changes: 6 additions & 5 deletions src/zimsplit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

#include <fstream>
#include <sstream>
#include <stdexcept>

#define ZIM_PRIVATE
Expand Down Expand Up @@ -188,12 +189,12 @@ int main(int argc, char* argv[])
{
try
{

std::string versionstr("zimsplit " + std::string(VERSION));
std::ostringstream versions;
printVersions(versions);
std::map<std::string, docopt::value> args = docopt::docopt(USAGE,
{argv + 1, argv + argc},
true,
versionstr);
{argv + 1, argv + argc},
true,
versions.str());

std::string prefix = args["<file>"].asString();
if (args["--prefix"])
Expand Down
17 changes: 2 additions & 15 deletions src/zimwriterfs/zimwriterfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,9 @@

#include "zimcreatorfs.h"
#include "../tools.h"
#include "../version.h"
#include "tools.h"

/* Check for version number */
#ifndef VERSION
#define VERSION "UNKNOWN"
#endif

namespace {
/* Command line options */
std::string language;
Expand Down Expand Up @@ -101,15 +97,6 @@ bool isVerbose()
return retVal;
}

/* Print current version defined in the macro */
void version()
{
// Access the version number through meson macro define
std::cout << "Version: " << "v" << VERSION << std::endl;
std::cout << "\tSee -h or --help argument flags for further argument options" << std::endl;
std::cout << "\tCopyright 2013-2016 Emmanuel Engelhart <kelson@kiwix.org>" << std::endl;
}

/* Print correct console usage options */
void usage()
{
Expand Down Expand Up @@ -239,7 +226,7 @@ void parse_args(int argc, char** argv)
tags = optarg;
break;
case 'V':
version();
printVersions();
exit(0);
break;
case 'h':
Expand Down
16 changes: 13 additions & 3 deletions test/zimcheck-test.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
#include <sstream>

#include "gtest/gtest.h"

#include "zim/zim.h"
#include "zim/archive.h"
#include "../src/zimcheck/checks.h"

std::string getLine(std::string str) {
std::istringstream f(str);
std::string line;
std::getline(f, line);
return line;
}

TEST(zimfilechecks, test_checksum)
{
Expand Down Expand Up @@ -172,20 +180,22 @@ TEST(zimcheck, help)

TEST(zimcheck, version)
{
std::string version = "zim-tools " + std::string(VERSION);

{
CapturedStdout zimcheck_output;
ASSERT_EQ(0, zimcheck({"zimcheck", "-v"}));
ASSERT_EQ(std::string(VERSION) + "\n", std::string(zimcheck_output));
ASSERT_EQ(version, getLine(std::string(zimcheck_output)));
}
{
CapturedStdout zimcheck_output;
ASSERT_EQ(0, zimcheck({"zimcheck", "-V"}));
ASSERT_EQ(std::string(VERSION) + "\n", std::string(zimcheck_output));
ASSERT_EQ(version, getLine(std::string(zimcheck_output)));
}
{
CapturedStdout zimcheck_output;
ASSERT_EQ(0, zimcheck({"zimcheck", "--version"}));
ASSERT_EQ(std::string(VERSION) + "\n", std::string(zimcheck_output));
ASSERT_EQ(version, getLine(std::string(zimcheck_output)));
}
}

Expand Down

0 comments on commit a26a450

Please sign in to comment.