bin: Adjust version display and help options.

In particular, this get rid of the ugly -? option that argp adds by
default, and we also remove -V so that we can use it for something
else later.

* src/bin/common_setup.cc, src/bin/common_setup.hh (misc_argp):
Provide support for --help/--version/--usage output, replacing argp's
default builting version.
* src/bin/genltl.cc, src/bin/ltl2tgba.cc, src/bin/ltl2tgta.cc,
src/bin/ltlcheck.cc, src/bin/ltlfilt.cc, src/bin/randltl.cc:
Call argp_parse() with ARGP_NO_HELP, and use misc_argp instead.
This commit is contained in:
Alexandre Duret-Lutz 2012-10-19 22:50:19 +02:00
parent c6030df936
commit b8ed85a30d
8 changed files with 64 additions and 9 deletions

View file

@ -19,6 +19,7 @@
#include "common_setup.hh"
#include "argp.h"
#include <cstdlib>
const char* argp_program_bug_address = "<" PACKAGE_BUGREPORT ">";
@ -29,9 +30,10 @@ display_version(FILE *stream, struct argp_state*)
fputs(" (" PACKAGE_STRING ")\n\
\n\
Copyright (C) 2012 Laboratoire de Recherche et Développement de l'Epita.\n\
This is free software; see the source for copying conditions. There is NO\n\
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,\n\
to the extent permitted by law.\n", stream);
License GPLv3+: \
GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n\
This is free software: you are free to change and redistribute it.\n\
There is NO WARRANTY, to the extent permitted by law.\n", stream);
}
void
@ -43,4 +45,49 @@ setup(char** argv)
argv[0] = const_cast<char*>(program_name);
argp_program_version_hook = display_version;
argp_err_exit_status = 2;
}
// argp's default behavior of offering -? for --help is just too silly.
// I mean, come on, why not also add -* to Darwinise more shell users?
// We disable this option as well as -V (because --version don't need
// a short version).
#define OPT_VERSION 1
#define OPT_HELP 2
#define OPT_USAGE 3
static const argp_option options[] =
{
{ "version", OPT_VERSION, 0, 0, "print program version", -1 },
{ "help", OPT_HELP, 0, 0, "print this help", -1 },
// We support this option just in case, but we don't advertise it.
{ "usage", OPT_USAGE, 0, OPTION_HIDDEN, "show short usage", -1 },
{ 0, 0, 0, 0, 0, 0 }
};
static int
parse_opt_misc(int key, char*, struct argp_state* state)
{
// This switch is alphabetically-ordered.
switch (key)
{
case OPT_VERSION:
display_version(state->out_stream, state);
exit(0);
break;
case OPT_HELP:
argp_state_help(state, state->out_stream, ARGP_HELP_STD_HELP);
break;
case OPT_USAGE:
argp_state_help(state, state->out_stream,
ARGP_HELP_USAGE | ARGP_HELP_EXIT_OK);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
const struct argp misc_argp = { options, parse_opt_misc, 0, 0, 0, 0, 0 };