cellar/src/version.cpp.cog

45 lines
1.3 KiB
Plaintext
Raw Normal View History

2017-03-22 20:13:24 -07:00
// vim: filetype=cpp :
#include <iostream>
2017-03-22 20:13:24 -07:00
#include "commands.hpp"
2017-03-22 20:13:24 -07:00
#include "version.hpp"
using namespace std;
using namespace cellar::version;
2017-03-22 20:13:24 -07:00
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"]
2017-03-22 20:42:08 -07:00
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]
2017-03-22 20:13:24 -07:00
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 \"{0}\";".format(outstring))
2017-03-22 20:13:24 -07:00
]]]*/
//[[[end]]]
}
void print_version(int argc, char** argv) {
cout << short_version() << endl;
}
bool _ = cellar::commands::add_command("version", &print_version);