Tue, 18 Feb 2025 19:02:53 +0100
add version output
and make -h and -V return 0
src/main.cpp | file | annotate | diff | comparison | revisions |
--- a/src/main.cpp Tue Feb 18 18:56:51 2025 +0100 +++ b/src/main.cpp Tue Feb 18 19:02:53 2025 +0100 @@ -36,6 +36,8 @@ using namespace std::chrono; +static constexpr auto program_version = "1.0.0"; + static void print_help() { fputs( "Usage: repoheat [OPTION]... [PATH]...\n\n" @@ -48,6 +50,7 @@ " -h, --help Print this help message\n" " -p, --pull Try to pull the repositories\n" " -s, --separate Output a separate heat map for each repository\n" + " -V, --version Output the version of this program and exit\n" " -y, --year <year> The year for which to create the heat map\n" " --hg <path> Path to hg binary (default: /usr/bin/hg)\n" " --git <path> Path to git binary (default: /usr/bin/git)\n\n" @@ -107,7 +110,7 @@ for (int i = 1; i < argc; i++) { if (chk_arg(argv[i], "-h", "--help")) { print_help(); - return -1; + return 1; } else if (chk_arg(argv[i], "-d", "--depth")) { if (i + 1 >= argc || parse_unsigned(argv[++i], &settings.depth, 256)) { fputs("missing or invalid depth\n", stderr); @@ -141,6 +144,9 @@ fputs("missing filename for authormap\n", stderr); return -1; } + } else if (chk_arg(argv[i], "-V", "--version")) { + printf("repoheat version %s\n", program_version); + return 1; } else if (chk_arg(argv[i], "--hg", nullptr)) { if (i + 1 < argc) { settings.hg.assign(argv[++i]); @@ -173,8 +179,8 @@ int main(int argc, char *argv[]) { // parse settings fm::settings settings; - if (parse_args(settings, argc, argv)) { - return EXIT_FAILURE; + if (int result = parse_args(settings, argc, argv); result != 0) { + return result < 0 ? EXIT_FAILURE : EXIT_SUCCESS; } // check hg and git