cellar/src/version.cpp.cog
2017-04-13 12:51:04 -07:00

49 lines
1.4 KiB
C++

// vim: filetype=cpp :
#include <iostream>
#include <string>
#include <vector>
#include "cellar.hpp"
#include "internal/core.hpp"
#include "commands.hpp"
#include "output.hpp"
#include "version.hpp"
using namespace std;
using namespace cellar::version;
string cellar::version::short_version() {
/*[[[cog
import cog
import configparser
import datetime
today = datetime.datetime.today()
cparse = configparser.ConfigParser()
cparse.read("cogrc")
config = cparse["version"]
if config.getboolean("release"):
outstring = "version {0}, built {1}".format(config["release_version"], str(today))
else:
try:
import subprocess
cmdoutput = subprocess.check_output(["git", "symbolic-ref", "HEAD"]).decode().strip()
gitbranch = cmdoutput.split("/")[2]
githash = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode().strip()
outstring = "{0} {1}, built {2}".format(gitbranch, githash, str(today))
except:
outstring = "exception raised when trying to read git data at precompile time"
raise
cog.outl("return string(\"{0}\");".format(outstring))
]]]*/
//[[[end]]]
}
void cellar::core::print_version(int argc, vector<string> argv) {
cellar::output::statement(short_version());
}