Add 'git-crypt version' command

This commit is contained in:
Andrew Ayer
2015-01-07 20:22:00 -08:00
parent 280bd43ac7
commit 12881f65fd
2 changed files with 19 additions and 0 deletions

View File

@@ -78,6 +78,11 @@ static void print_usage (std::ostream& out)
out << "See 'git-crypt help COMMAND' for more information on a specific command." << std::endl;
}
static void print_version (std::ostream& out)
{
out << "git-crypt " << VERSION << std::endl;
}
static bool help_for_command (const char* command, std::ostream& out)
{
if (std::strcmp(command, "init") == 0) {
@@ -121,6 +126,12 @@ static int help (int argc, const char** argv)
return 0;
}
static int version (int argc, const char** argv)
{
print_version(std::cout);
return 0;
}
int main (int argc, const char** argv)
try {
@@ -141,6 +152,9 @@ try {
if (std::strcmp(argv[arg_index], "--help") == 0) {
print_usage(std::clog);
return 0;
} else if (std::strcmp(argv[arg_index], "--version") == 0) {
print_version(std::clog);
return 0;
} else if (std::strcmp(argv[arg_index], "--") == 0) {
++arg_index;
break;
@@ -171,6 +185,9 @@ try {
if (std::strcmp(command, "help") == 0) {
return help(argc, argv);
}
if (std::strcmp(command, "version") == 0) {
return version(argc, argv);
}
if (std::strcmp(command, "init") == 0) {
return init(argc, argv);
}

View File

@@ -31,6 +31,8 @@
#ifndef GIT_CRYPT_GIT_CRYPT_HPP
#define GIT_CRYPT_GIT_CRYPT_HPP
#define VERSION "0.4.0"
extern const char* argv0; // initialized in main() to argv[0]
#endif