build+core: Add printing of version number in daemons and tools
This commit also changes how version number is handled. Version is now
fully controlled from top-level wscript. In addition to that, a new
NFD_VERSION_BUILD_STRING macro is set to include more detailed
information, including commit ID (e.g., "0.1.0-rc1-1-g5c86570").
Change-Id: I448eb627e0c42dc814de1107cf7bb0dc94fa2a89
Refs: #1575
diff --git a/rib/main.cpp b/rib/main.cpp
index 1593784..d74ed8d 100644
--- a/rib/main.cpp
+++ b/rib/main.cpp
@@ -25,6 +25,7 @@
#include <getopt.h>
+#include "version.hpp"
#include "common.hpp"
#include "rib-manager.hpp"
#include "core/config-file.hpp"
@@ -39,6 +40,7 @@
struct ProgramOptions
{
bool showUsage;
+ bool showVersion;
bool showModules;
std::string config;
};
@@ -107,7 +109,9 @@
<< "Run NRD daemon\n"
<< "\n"
<< "Options:\n"
- << " [--help] - print this help message\n"
+ << " [--help] - print this help message\n"
+ << " [--version] - print version and exit\n"
+ << " [--modules] - list available logging modules\n"
<< " [--config /path/to/nfd.conf] - path to configuration file "
<< "(default: " << DEFAULT_CONFIG_FILE << ")\n"
;
@@ -131,6 +135,7 @@
parseCommandLine(int argc, char** argv, ProgramOptions& options)
{
options.showUsage = false;
+ options.showVersion = false;
options.showModules = false;
options.config = DEFAULT_CONFIG_FILE;
@@ -140,6 +145,7 @@
{ "help" , no_argument , 0, 0 },
{ "modules", no_argument , 0, 0 },
{ "config" , required_argument, 0, 0 },
+ { "version", no_argument , 0, 0 },
{ 0 , 0 , 0, 0 }
};
int c = getopt_long_only(argc, argv, "", longOptions, &optionIndex);
@@ -147,21 +153,24 @@
break;
switch (c) {
- case 0:
- switch (optionIndex) {
- case 0: // help
- options.showUsage = true;
- break;
- case 1: // modules
- options.showModules = true;
- break;
- case 2: // config
- options.config = ::optarg;
- break;
- default:
- return false;
- }
+ case 0:
+ switch (optionIndex) {
+ case 0: // help
+ options.showUsage = true;
break;
+ case 1: // modules
+ options.showModules = true;
+ break;
+ case 2: // config
+ options.config = ::optarg;
+ break;
+ case 3: // version
+ options.showVersion = true;
+ break;
+ default:
+ return false;
+ }
+ break;
}
}
return true;
@@ -218,6 +227,11 @@
return 0;
}
+ if (options.showVersion) {
+ std::cout << NFD_VERSION_BUILD_STRING << std::endl;
+ return 0;
+ }
+
Nrd nrdInstance;
try {