Add Git-derived version reporting

This commit is contained in:
deeaitch committed 2026-08-28 01:30:44 -04:00
1 parent 7026e246bb
commit 6ed48022ae
3 files changed
+59 -4

No files matched your search

+19 -3
View File
@@ -9,6 +9,10 @@
#include "convertorg.h"
#include "typefactory.h"
#ifndef KINDLE2NOTES_VERSION
#define KINDLE2NOTES_VERSION "unknown"
#endif
using ConverterFactory = TypeFactory<std::string, Converter, std::string>;
static constexpr std::array<const char *, 4> kSupportedTypes = {
@@ -19,11 +23,13 @@ struct CliArgs {
std::string input;
std::string output;
std::string type;
bool version = false;
};
static void print_usage (const char *argv0) {
std::cerr << "Usage: " << argv0
<< " --input <file> --output <file> --type <type>\n";
<< " --input <file> --output <file> --type <type>\n"
<< " " << argv0 << " --version\n";
}
static void print_supported_types() {
@@ -47,12 +53,13 @@ static bool parse_args (int argc, char **argv, CliArgs &out) {
{"input", required_argument, nullptr, 'i'},
{"output", required_argument, nullptr, 'o'},
{"type", required_argument, nullptr, 't'},
{"version", no_argument, nullptr, 'v'},
{"help", no_argument, nullptr, 'h'},
{nullptr, 0, nullptr, 0 }
};
int c = 0;
while ((c = ::getopt_long (argc, argv, "i:o:t:h", long_opts, nullptr)) != -1) {
while ((c = ::getopt_long (argc, argv, "i:o:t:vh", long_opts, nullptr)) != -1) {
switch (c) {
case 'i':
out.input = optarg;
@@ -63,6 +70,9 @@ static bool parse_args (int argc, char **argv, CliArgs &out) {
case 't':
out.type = optarg;
break;
case 'v':
out.version = true;
break;
case 'h':
print_usage (argv[0]);
return false;
@@ -72,7 +82,8 @@ static bool parse_args (int argc, char **argv, CliArgs &out) {
}
}
if (out.input.empty() || out.output.empty() || out.type.empty()) {
if (!out.version &&
(out.input.empty() || out.output.empty() || out.type.empty())) {
print_usage (argv[0]);
return false;
}
@@ -85,6 +96,11 @@ int main (int argc, char **argv) {
if (!parse_args (argc, argv, args))
return 1;
if (args.version) {
std::cout << "kindle2notes " << KINDLE2NOTES_VERSION << '\n';
return 0;
}
const ConverterFactory factory = build_converter_factory();
if (!factory.contains (args.type)) {
std::cerr << "Unsupported output type: " << args.type << '\n';