Add option --lib-version to gpgme-tool.

* src/gpgme-tool.c (options, parse_options):  Add --lib-version
(CMD_LIBVERSION): New.
(main): Implement.
This commit is contained in:
Werner Koch 2015-07-23 11:40:09 +02:00
parent a5d9e018b8
commit c23f889710
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B

View File

@ -3728,6 +3728,7 @@ static char args_doc[] = "COMMAND [OPTIONS...]";
static struct argp_option options[] = { static struct argp_option options[] = {
{ "server", 's', 0, 0, "Server mode" }, { "server", 's', 0, 0, "Server mode" },
{ "gpg-binary", 501, "FILE", 0, "Use FILE for the GPG backend" }, { "gpg-binary", 501, "FILE", 0, "Use FILE for the GPG backend" },
{ "lib-version", 502, 0, 0, "Show library version" },
{ 0 } { 0 }
}; };
@ -3736,7 +3737,7 @@ static struct argp argp = { options, parse_options, args_doc, doc };
struct args struct args
{ {
enum { CMD_DEFAULT, CMD_SERVER } cmd; enum { CMD_DEFAULT, CMD_SERVER, CMD_LIBVERSION } cmd;
const char *gpg_binary; const char *gpg_binary;
}; };
@ -3762,6 +3763,11 @@ parse_options (int key, char *arg, struct argp_state *state)
case 501: case 501:
args->gpg_binary = arg; args->gpg_binary = arg;
break; break;
case 502:
args->cmd = CMD_LIBVERSION;
break;
#if 0 #if 0
case ARGP_KEY_ARG: case ARGP_KEY_ARG:
if (state->arg_num >= 2) if (state->arg_num >= 2)
@ -3787,6 +3793,7 @@ main (int argc, char *argv[])
struct args args; struct args args;
struct gpgme_tool gt; struct gpgme_tool gt;
gpg_error_t err; gpg_error_t err;
int needgt = 1;
#ifdef HAVE_SETLOCALE #ifdef HAVE_SETLOCALE
setlocale (LC_ALL, ""); setlocale (LC_ALL, "");
@ -3804,7 +3811,10 @@ main (int argc, char *argv[])
argp_parse (&argp, argc, argv, 0, 0, &args); argp_parse (&argp, argc, argv, 0, 0, &args);
log_init (); log_init ();
if (args.gpg_binary) if (args.cmd == CMD_LIBVERSION)
needgt = 0;
if (needgt && args.gpg_binary)
{ {
if (access (args.gpg_binary, X_OK)) if (access (args.gpg_binary, X_OK))
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
@ -3816,6 +3826,7 @@ main (int argc, char *argv[])
args.gpg_binary); args.gpg_binary);
} }
if (needgt)
gt_init (&gt); gt_init (&gt);
switch (args.cmd) switch (args.cmd)
@ -3824,8 +3835,16 @@ main (int argc, char *argv[])
case CMD_SERVER: case CMD_SERVER:
gpgme_server (&gt); gpgme_server (&gt);
break; break;
case CMD_LIBVERSION:
printf ("Version from header: %s (0x%06x)\n",
GPGME_VERSION, GPGME_VERSION_NUMBER);
printf ("Version from binary: %s\n", gpgme_check_version (NULL));
printf ("Copyright blurb ...:%s\n", gpgme_check_version ("\x01\x01"));
break;
} }
if (needgt)
gpgme_release (gt.ctx); gpgme_release (gt.ctx);
#ifdef HAVE_W32CE_SYSTEM #ifdef HAVE_W32CE_SYSTEM