Compare commits

...

2 Commits

Author SHA1 Message Date
94ade7238e CLI: Add 'version' command 2021-10-03 23:04:46 +02:00
fa5e75893f Add version.{h,cpp}: Returning version info 2021-10-03 23:01:19 +02:00
6 changed files with 30 additions and 6 deletions

View File

@ -55,6 +55,8 @@ gtest: $(GTESTS_TESTDIR)/*.cpp $(GTEST_OBJECTS)
%.o:%.cpp
$(CXX) ${CXXFLAGS} ${LDFLAGS} ${INCLUDEFLAGS} -c -o $@ $<
version.o:version.cpp
$(CXX) ${CXXFLAGS} ${LDFLAGS} ${INCLUDEFLAGS} -DGITCOMMIT=\"$(shell git rev-parse --short HEAD)\" -c -o $@ $<
clean:
rm -f $(OBJECTS) $(DEPENDS)

View File

@ -8,6 +8,7 @@
#include "authenticator.h"
#include "config.h"
#include "logger.h"
#include "version.h"
CLIHandler::CLIHandler(Config &config, Database &db)
{
@ -218,3 +219,8 @@ std::pair<std::string, std::vector<std::string>> CLIHandler::splitCommand(std::s
splitted.erase(splitted.begin());
return {cmd, splitted};
}
std::pair<bool, std::string> CLIHandler::version(const std::vector<std::string> &args)
{
return {true, get_version_string()};
}

4
cli.h
View File

@ -30,6 +30,7 @@ class CLIHandler
std::pair<bool, std::string> user_set_perms(const std::vector<std::string> &args);
std::pair<bool, std::string> user_list(const std::vector<std::string> &args);
std::pair<bool, std::string> user_show(const std::vector<std::string> &args);
std::pair<bool, std::string> version(const std::vector<std::string> &args);
std::vector<struct cmd> cmds{
{{"user",
@ -52,7 +53,8 @@ class CLIHandler
return {true, ""};
}},
{"help", "print this help", 0, {}, &CLIHandler::cli_help},
{"attach", "attach to running instance", 0, {}, &CLIHandler::attach}}};
{"attach", "attach to running instance", 0, {}, &CLIHandler::attach},
{"version", "print verison info", 0, {}, &CLIHandler::version}}};
std::pair<bool, std::string> processCommand(const std::vector<CLIHandler::cmd> &commands, std::string cmd,
const std::vector<std::string> &args);

View File

@ -41,6 +41,7 @@ SOFTWARE.
#include "cli.h"
#include "cliconsole.h"
#include "cliserver.h"
#include "version.h"
void sigterm_handler(int arg)
{
@ -73,11 +74,6 @@ std::unique_ptr<ICache> createCache(const ConfigVariableResolver &resolver)
return std::make_unique<FsCache>(path);
}
std::string get_version_string()
{
return "master";
}
int main(int argc, char **argv)
{

11
version.cpp Normal file
View File

@ -0,0 +1,11 @@
#include "version.h"
std::string git_commit_id()
{
return std::string(GITCOMMIT);
}
std::string get_version_string()
{
return git_commit_id() + " Built: " + __DATE__ + " " + __TIME__;
}

7
version.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef VERSION_H
#define VERSION_H
#include <string>
std::string git_commit_id();
std::string get_version_string();
#endif // VERSION_H