Commit c86c4efb authored by Daniel Salzman's avatar Daniel Salzman

utils: unify version and help parameters

parent 4be73a46
......@@ -83,7 +83,7 @@ specification. The default class is IN.
Enable debug messages.
.TP
\fB\-h\fP, \fB\-\-help\fP
Print help and usage.
Print the program help.
.TP
\fB\-k\fP \fIkeyfile\fP
Use the TSIG key stored in a file \fIkeyfile\fP to authenticate the request. The
......@@ -103,7 +103,7 @@ variant of \fItype\fP specification. The default type is A. IXFR type requires
SOA serial parameter. NOTIFY type without SOA serial parameter causes pure
NOTIFY message without any SOA hint.
.TP
\fB\-v\fP, \fB\-\-version\fP
\fB\-V\fP, \fB\-\-version\fP
Print the program version.
.TP
\fB\-x\fP \fIaddress\fP
......
......@@ -68,7 +68,7 @@ Send ANY query with verbose mode.
Enable debug messages.
.TP
\fB\-h\fP, \fB\-\-help\fP
Print help and usage.
Print the program help.
.TP
\fB\-r\fP
Disable recursion.
......
......@@ -55,11 +55,11 @@ Raw output, do not reformat via \fBknotc\fP\&.
\fB\-p\fP, \fB\-\-path\fP \fIdirectory\fP
Path to \fBknotc\fP utility.
.TP
\fB\-V\fP, \fB\-\-version\fP
Print program version.
.TP
\fB\-h\fP, \fB\-\-help\fP
Print help and usage.
Print the program help.
.TP
\fB\-V\fP, \fB\-\-version\fP
Print the program version.
.UNINDENT
.SH SEE ALSO
.sp
......
......@@ -41,16 +41,17 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
Use a textual configuration file (default is \fB@config_dir@/knot.conf\fP).
.TP
\fB\-C\fP, \fB\-\-confdb\fP \fIdirectory\fP
Use a binary configuration database.
Use a binary configuration database directory.
.TP
\fB\-d\fP, \fB\-\-daemonize\fP [\fIdirectory\fP]
Run the server as a daemon. Working directory may be set (default is \fB/\fP).
.TP
\fB\-V\fP, \fB\-\-version\fP
Print the program versiom.
Run the server as a daemon. New root directory may be specified
(default is \fB/\fP).
.TP
\fB\-h\fP, \fB\-\-help\fP
Print help and usage.
Print the program help.
.TP
\fB\-V\fP, \fB\-\-version\fP
Print the program version.
.UNINDENT
.SH SEE ALSO
.sp
......
......@@ -49,7 +49,7 @@ comments and are not processed.
Enable debug messages.
.TP
\fB\-h\fP, \fB\-\-help\fP
Print help and usage.
Print the program help.
.TP
\fB\-k\fP \fIkeyfile\fP
Use the TSIG key stored in a file \fIkeyfile\fP to authenticate the request. The
......
......@@ -60,7 +60,7 @@ Options
Enable debug messages.
**-h**, **--help**
Print help and usage.
Print the program help.
**-k** *keyfile*
Use the TSIG key stored in a file *keyfile* to authenticate the request. The
......@@ -80,7 +80,7 @@ Options
SOA serial parameter. NOTIFY type without SOA serial parameter causes pure
NOTIFY message without any SOA hint.
**-v**, **--version**
**-V**, **--version**
Print the program version.
**-x** *address*
......
......@@ -45,7 +45,7 @@ Options
Enable debug messages.
**-h**, **--help**
Print help and usage.
Print the program help.
**-r**
Disable recursion.
......
......@@ -32,11 +32,11 @@ Options
**-p**, **--path** *directory*
Path to :program:`knotc` utility.
**-V**, **--version**
Print program version.
**-h**, **--help**
Print help and usage.
Print the program help.
**-V**, **--version**
Print the program version.
See Also
--------
......
......@@ -18,16 +18,17 @@ Parameters
Use a textual configuration file (default is :file:`@config_dir@/knot.conf`).
**-C**, **--confdb** *directory*
Use a binary configuration database.
Use a binary configuration database directory.
**-d**, **--daemonize** [*directory*]
Run the server as a daemon. Working directory may be set (default is :file:`/`).
**-V**, **--version**
Print the program versiom.
Run the server as a daemon. New root directory may be specified
(default is :file:`/`).
**-h**, **--help**
Print help and usage.
Print the program help.
**-V**, **--version**
Print the program version.
See Also
--------
......
......@@ -26,7 +26,7 @@ Options
Enable debug messages.
**-h**, **--help**
Print help and usage.
Print the program help.
**-k** *keyfile*
Use the TSIG key stored in a file *keyfile* to authenticate the request. The
......
......@@ -37,6 +37,8 @@
#include "strtonum.h"
#include "wire.h"
#define PROGRAM_NAME "keymgr"
#define DEFAULT_POLICY "default"
#define DEFAULT_KEYSTORE "default"
......@@ -1563,12 +1565,12 @@ static int cmd_tsig(int argc, char *argv[])
static void print_help(void)
{
printf("Please, see keymgr(8) manual page.\n");
printf("Please, see %s(8) manual page.\n", PROGRAM_NAME);
}
static void print_version(void)
{
printf("keymgr, version %s\n", PACKAGE_VERSION);
printf("%s (Knot DNS), version %s\n", PROGRAM_NAME, PACKAGE_VERSION);
}
int main(int argc, char *argv[])
......
......@@ -32,14 +32,20 @@
#define PROGRAM_NAME "knsec3hash"
/*!
* \brief Print program usage (and example).
* \brief Print program help (and example).
*/
static void usage(FILE *stream)
static void print_help(void)
{
fprintf(stream, "usage: " PROGRAM_NAME " "
"<salt> <algorithm> <iterations> <domain-name>\n");
fprintf(stream, "example: " PROGRAM_NAME " "
"c01dcafe 1 10 knot-dns.cz\n");
printf("Usage: " PROGRAM_NAME " <salt> <algorithm> <iterations> <domain-name>\n");
printf("Example: " PROGRAM_NAME " c01dcafe 1 10 knot-dns.cz\n");
}
/*!
* \brief Print program version.
*/
static void print_version(void)
{
printf("%s (Knot DNS), version %s\n", PROGRAM_NAME, PACKAGE_VERSION);
}
/*!
......@@ -102,8 +108,8 @@ static bool parse_nsec3_params(dnssec_nsec3_params_t *params, const char *salt_s
int main(int argc, char *argv[])
{
struct option options[] = {
{ "version", no_argument, 0, 'V' },
{ "help", no_argument, 0, 'h' },
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
{ NULL }
};
......@@ -111,21 +117,21 @@ int main(int argc, char *argv[])
int li = 0;
while ((opt = getopt_long(argc, argv, "hV", options, &li)) != -1) {
switch(opt) {
case 'V':
printf("%s, version %s\n", PROGRAM_NAME, PACKAGE_VERSION);
return 0;
case 'h':
usage(stdout);
print_help();
return 0;
case 'V':
print_version();
return 0;
default:
usage(stderr);
print_help();
return 1;
}
}
// knsec3hash <salt> <algorithm> <iterations> <domain>
if (argc != 5) {
usage(stderr);
print_help();
return 1;
}
......
......@@ -41,6 +41,8 @@
#include "knot/server/tcp-handler.h"
#include "knot/zone/timers.h"
#define PROGRAM_NAME "knotd"
/* Signal flags. */
static volatile bool sig_req_stop = false;
static volatile bool sig_req_reload = false;
......@@ -236,41 +238,46 @@ static void event_loop(server_t *server)
remote_unbind(&addr, remote);
}
static void help(void)
static void print_help(void)
{
printf("Usage: %sd [parameters]\n",
PACKAGE_NAME);
printf("\nParameters:\n"
" -c, --config <file> Select configuration file.\n"
printf("Usage: %s [parameters]\n"
"\n"
"Parameters:\n"
" -c, --config <file> Use a textual configuration file.\n"
" (default %s)\n"
" -C, --confdb <dir> Select configuration database directory.\n"
" -d, --daemonize=[dir] Run server as a daemon.\n"
" -V, --version Print version of the server.\n"
" -h, --help Print help and usage.\n",
CONF_DEFAULT_FILE);
" -C, --confdb <dir> Use a binary configuration database directory.\n"
" -d, --daemonize=[dir] Run the server as a daemon (with new root directory).\n"
" -h, --help Print the program help.\n"
" -V, --version Print the program version.\n",
PROGRAM_NAME, CONF_DEFAULT_FILE);
}
static void print_version(void)
{
printf("%s (Knot DNS), version %s\n", PROGRAM_NAME, PACKAGE_VERSION);
}
int main(int argc, char **argv)
{
/* Parse command line arguments. */
int c = 0, li = 0;
int daemonize = 0;
bool daemonize = false;
const char *config_fn = CONF_DEFAULT_FILE;
const char *config_db = NULL;
const char *daemon_root = "/";
/* Long options. */
struct option opts[] = {
{"config", required_argument, 0, 'c' },
{"confdb", required_argument, 0, 'C' },
{"daemonize", optional_argument, 0, 'd'},
{"version", no_argument, 0, 'V'},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
{ "config", required_argument, 0, 'c' },
{ "confdb", required_argument, 0, 'C' },
{ "daemonize", optional_argument, 0, 'd' },
{ "help", no_argument, 0, 'h' },
{ "version", no_argument, 0, 'V' },
{ NULL }
};
while ((c = getopt_long(argc, argv, "c:C:dVh", opts, &li)) != -1) {
switch (c) {
/* Parse command line arguments. */
int opt = 0, li = 0;
while ((opt = getopt_long(argc, argv, "c:C:dhV", opts, &li)) != -1) {
switch (opt) {
case 'c':
config_fn = optarg;
break;
......@@ -278,27 +285,26 @@ int main(int argc, char **argv)
config_db = optarg;
break;
case 'd':
daemonize = 1;
daemonize = true;
if (optarg) {
daemon_root = optarg;
}
break;
case 'V':
printf("%s, version %s\n", "Knot DNS", PACKAGE_VERSION);
return EXIT_SUCCESS;
case 'h':
case '?':
help();
print_help();
return EXIT_SUCCESS;
case 'V':
print_version();
return EXIT_SUCCESS;
default:
help();
print_help();
return EXIT_FAILURE;
}
}
/* Check for non-option parameters. */
if (argc - optind > 0) {
help();
print_help();
return EXIT_FAILURE;
}
......
......@@ -116,6 +116,11 @@ typedef struct {
param_handle_f handler;
} param_t;
inline static void print_version(const char *program_name)
{
printf("%s (Knot DNS), version %s\n", program_name, PACKAGE_VERSION);
}
/*!
* \brief Transforms localized IDN string to ASCII punycode.
*
......
......@@ -30,6 +30,8 @@
#include "contrib/sockaddr.h"
#include "contrib/ucw/lists.h"
#define PROGRAM_NAME "kdig"
#define DEFAULT_RETRIES_DIG 2
#define DEFAULT_TIMEOUT_DIG 5
......@@ -1327,9 +1329,9 @@ void complete_queries(list_t *queries, const query_t *conf)
}
}
static void kdig_help(void)
static void print_help(void)
{
printf("Usage: kdig [-4] [-6] [-dh] [-b address] [-c class] [-p port]\n"
printf("Usage: %s [-4] [-6] [-dh] [-b address] [-c class] [-p port]\n"
" [-q name] [-t type] [-x address] [-k keyfile]\n"
" [-y [algo:]keyname:key] [-E tapfile] [-G tapfile]\n"
" name [type] [class] [@server]\n"
......@@ -1368,8 +1370,9 @@ static void kdig_help(void)
" +retry=N Set number of retries.\n"
" +bufsize=B Set EDNS buffer size.\n"
"\n"
" -h, --help Print help.\n"
" -v, --version Print program version.\n");
" -h, --help Print the program help.\n"
" -V, --version Print the program version.\n",
PROGRAM_NAME);
}
static int parse_opt1(const char *opt, const char *value, kdig_params_t *params,
......@@ -1431,7 +1434,7 @@ static int parse_opt1(const char *opt, const char *value, kdig_params_t *params,
return KNOT_ENOTSUP;
}
kdig_help();
print_help();
params->stop = true;
break;
case 'c':
......@@ -1495,13 +1498,13 @@ static int parse_opt1(const char *opt, const char *value, kdig_params_t *params,
}
*index += add;
break;
case 'v':
case 'V':
if (len > 1) {
ERR("invalid option -%s\n", opt);
return KNOT_ENOTSUP;
}
printf(KDIG_VERSION);
print_version(PROGRAM_NAME);
params->stop = true;
break;
case 'x':
......@@ -1574,10 +1577,10 @@ static int parse_opt1(const char *opt, const char *value, kdig_params_t *params,
break;
case '-':
if (strcmp(opt, "-help") == 0) {
kdig_help();
print_help();
params->stop = true;
} else if (strcmp(opt, "-version") == 0) {
printf(KDIG_VERSION);
print_version(PROGRAM_NAME);
params->stop = true;
} else {
ERR("invalid option: -%s\n", opt);
......@@ -1728,7 +1731,7 @@ int kdig_parse(kdig_params_t *params, int argc, char *argv[])
}
break;
case KNOT_ENOTSUP:
kdig_help();
print_help();
default: // Fall through.
return ret;
}
......
......@@ -39,8 +39,6 @@
# include "contrib/dnstap/writer.h"
#endif // USE_DNSTAP
#define KDIG_VERSION "kdig, version " PACKAGE_VERSION "\n"
/*! \brief Operation mode of kdig. */
typedef enum {
/*!< Standard 1-message query/reply. */
......
......@@ -28,6 +28,8 @@
#include "libknot/libknot.h"
#include "contrib/ucw/lists.h"
#define PROGRAM_NAME "khost"
#define DEFAULT_RETRIES_HOST 1
#define DEFAULT_TIMEOUT_HOST 2
......@@ -191,31 +193,29 @@ static int parse_name(const char *value, list_t *queries, const query_t *conf)
return KNOT_EOK;
}
static void khost_help(void)
static void print_help(void)
{
printf("Usage: khost [-4] [-6] [-adhrsTvVw] [-c class] [-t type]\n"
printf("Usage: %s [-4] [-6] [-adhrsTvVw] [-c class] [-t type]\n"
" [-R retries] [-W time] name [server]\n\n"
" -4 Use IPv4 protocol only.\n"
" -6 Use IPv6 procotol only.\n"
" -a Same as -t ANY -v.\n"
" -d Allow debug messages.\n"
" -h, --help Print help.\n"
" -h, --help Print the program help.\n"
" -r Disable recursion.\n"
" -T Use TCP procotol.\n"
" -v Verbose output.\n"
" -V, --version Print program version.\n"
" -V, --version Print the program version.\n"
" -w Wait forever.\n"
" -c Set query class.\n"
" -t Set query type.\n"
" -R Set number of UDP retries.\n"
" -W Set wait interval.\n"
);
" -W Set wait interval.\n",
PROGRAM_NAME);
}
int khost_parse(kdig_params_t *params, int argc, char *argv[])
{
int opt = 0, li = 0;
if (params == NULL || argv == NULL) {
DBG_NULL;
return KNOT_EINVAL;
......@@ -239,12 +239,13 @@ int khost_parse(kdig_params_t *params, int argc, char *argv[])
// Long options.
struct option opts[] = {
{ "version", no_argument, 0, 'V' },
{ "help", no_argument, 0, 'h' },
{ 0, 0, 0, 0 }
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
{ NULL }
};
// Command line options processing.
int opt = 0, li = 0;
while ((opt = getopt_long(argc, argv, "46adhrsTvVwc:t:R:W:", opts, &li))
!= -1) {
switch (opt) {
......@@ -265,7 +266,7 @@ int khost_parse(kdig_params_t *params, int argc, char *argv[])
msg_enable_debug(1);
break;
case 'h':
khost_help();
print_help();
params->stop = false;
return KNOT_EOK;
case 'r':
......@@ -281,7 +282,7 @@ int khost_parse(kdig_params_t *params, int argc, char *argv[])
conf->style.show_footer = true;
break;
case 'V':
printf(KHOST_VERSION);
print_version(PROGRAM_NAME);
params->stop = false;
return KNOT_EOK;
case 'w':
......@@ -323,7 +324,7 @@ int khost_parse(kdig_params_t *params, int argc, char *argv[])
}
break;
default:
khost_help();
print_help();
return KNOT_ENOTSUP;
}
}
......@@ -343,7 +344,7 @@ int khost_parse(kdig_params_t *params, int argc, char *argv[])
}
break;
default:
khost_help();
print_help();
return KNOT_ENOTSUP;
}
......
......@@ -28,8 +28,6 @@
#include "utils/kdig/kdig_params.h"
#define KHOST_VERSION "khost, version " PACKAGE_VERSION "\n"
int khost_parse(kdig_params_t *params, int argc, char *argv[]);
void khost_clean(kdig_params_t *params);
......
......@@ -20,12 +20,13 @@
#include <stdlib.h>
#include <unistd.h>
#include "utils/common/params.h"
#include "utils/knot1to2/extra.h"
#include "utils/knot1to2/scheme.h"
#include "contrib/hat-trie/hat-trie.h"
#include "contrib/string.h"
#define KNOT1TO2_VERSION "knot1to2, version " PACKAGE_VERSION "\n"
#define PROGRAM_NAME "knot1to2"
static int run_parser(const char *file_in, int run, share_t *share)
{
......@@ -142,23 +143,24 @@ static int reformat(const char *file_out, const char *file_in, const char *path)
return 0;
}
void help(void)
static void print_help(void)
{
printf("Usage: knot1to2 [options] -i <file> -o <file>\n");
printf("\n"
printf("Usage: %s [options] -i <file> -o <file>\n"
"\n"
" -i, --in <file> Input config file (Knot version 1.x).\n"
" -o, --out <file> Output config file (Knot version 2.x).\n"
"\nOptions:\n"
"\n"
"Options:\n"
" -p, --path <dir> Path to knotc utility.\n"
" -r, --raw Raw output, do not reformat via knotc.\n"
"\n"
" -v, --version Print package version.\n"
" -h, --help Print help and usage.\n");
" -h, --help Print the program help.\n"
" -V, --version Print the program version.\n",
PROGRAM_NAME);
}
int main(int argc, char **argv)
{
int c = 0, li = 0;
const char *file_in = NULL;
const char *file_out = NULL;
const char *path = NULL;
......@@ -169,14 +171,15 @@ int main(int argc, char **argv)
{ "out", required_argument, NULL, 'o' },
{ "path", required_argument, NULL, 'p' },
{ "raw", no_argument, NULL, 'r' },
{ "version", no_argument, NULL, 'v' },
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
{ NULL }
};
// Parse parameters.
while ((c = getopt_long(argc, argv, "i:o:p:rvh", opts, &li)) != -1) {
switch (c)
int opt = 0, li = 0;
while ((opt = getopt_long(argc, argv, "i:o:p:rhV", opts, &li)) != -1) {
switch (opt)
{
case 'i':
file_in = optarg;
......@@ -190,21 +193,21 @@ int main(int argc, char **argv)
case 'r':
raw = true;
break;
case 'v':
printf(KNOT1TO2_VERSION);
return EXIT_SUCCESS;
case 'h':
help();
print_help();
return EXIT_SUCCESS;
case 'V':
print_version(PROGRAM_NAME);
return EXIT_SUCCESS;
default:
help();
print_help();
return EXIT_FAILURE;
}
}
// Check for missing or invalid parameters.
if (argc - optind > 0 || file_in == NULL || file_out == NULL) {
help();
print_help();
return EXIT_FAILURE;
}
......
......@@ -29,6 +29,8 @@
#include "contrib/mempattern.h"
#include "contrib/ucw/mempool.h"
#define PROGRAM_NAME "knsupdate"
#define DEFAULT_RETRIES_NSUPDATE 3
#define DEFAULT_TIMEOUT_NSUPDATE 12
......@@ -174,34 +176,33 @@ void knsupdate_reset(knsupdate_params_t *params)
rr_list_free(&params->prereq_list, &params->mm);
}
static void knsupdate_help(void)
static void print_help(void)
{
printf("Usage: knsupdate [-d] [-v] [-k keyfile | -y [hmac:]name:key]\n"
" [-p port] [-t timeout] [-r retries] [filename]\n");
printf("Usage: %s [-d] [-v] [-k keyfile | -y [hmac:]name:key]\n"
" [-p port] [-t timeout] [-r retries] [filename]\n",
PROGRAM_NAME);
}
int knsupdate_parse(knsupdate_params_t *params, int argc, char *argv[])
{
int opt = 0, li = 0;
int ret = KNOT_EOK;
if (params == NULL || argv == NULL) {
return KNOT_EINVAL;
}
ret = knsupdate_init(params);
int ret = knsupdate_init(params);
if (ret != KNOT_EOK) {
return ret;
}
// Long options.
struct option opts[] = {
{ "version", no_argument, 0, 'V' },
{ "help", no_argument, 0, 'h' },
{ 0, 0, 0, 0 }
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
{ NULL }
};
/* Command line options processing. */
int opt = 0, li = 0;
while ((opt = getopt_long(argc, argv, "dhDvVp:t:r:y:k:", opts, &li))
!= -1) {
switch (opt) {
......@@ -210,14 +211,14 @@ int knsupdate_parse(knsupdate_params_t *params, int argc, char *argv[])
msg_enable_debug(1);
break;
case 'h':
knsupdate_help();
print_help();
params->stop = true;
return KNOT_EOK;
case 'v':
params->protocol = PROTO_TCP;
break;
case 'V':
printf(KNSUPDATE_VERSION);
print_version(PROGRAM_NAME);
params->stop = true;
return KNOT_EOK;
case 'p':
......@@ -257,7 +258,7 @@ int knsupdate_parse(knsupdate_params_t *params, int argc, char *argv[])
}
break;
default:
knsupdate_help();
print_help();
return KNOT_ENOTSUP;
}
}
......
......@@ -35,11 +35,6 @@
#include "zscanner/scanner.h"
#include "contrib/ucw/lists.h"
#define KNSUPDATE_VERSION "knsupdate, version " PACKAGE_VERSION "\n"
/*! Parser init string. */
#define PARSER_INIT_STR "$ORIGIN %s\n$TTL %u\n"
/*! \brief knsupdate-specific params data. */
typedef struct {
/*!< Stop processing - just print help, version,... */
......