From 12881f65fd046f06f7535e2e44d828311232e374 Mon Sep 17 00:00:00 2001 From: Andrew Ayer Date: Wed, 7 Jan 2015 20:22:00 -0800 Subject: [PATCH] Add 'git-crypt version' command --- git-crypt.cpp | 17 +++++++++++++++++ git-crypt.hpp | 2 ++ 2 files changed, 19 insertions(+) diff --git a/git-crypt.cpp b/git-crypt.cpp index 816bf2e..9505834 100644 --- a/git-crypt.cpp +++ b/git-crypt.cpp @@ -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); } diff --git a/git-crypt.hpp b/git-crypt.hpp index 94b1ded..6df62d8 100644 --- a/git-crypt.hpp +++ b/git-crypt.hpp @@ -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