From 292f7858e60b0dffd8c06f6818d90ccf3b34e0b2 Mon Sep 17 00:00:00 2001 From: Pavel Tvrdik Date: Thu, 8 Sep 2016 16:27:40 +0200 Subject: [PATCH] Main: Improve BIRD help messages --- sysdep/unix/main.c | 60 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 11 deletions(-) diff --git a/sysdep/unix/main.c b/sysdep/unix/main.c index 11a4acc6..a7989920 100644 --- a/sysdep/unix/main.c +++ b/sysdep/unix/main.c @@ -617,7 +617,7 @@ signal_init(void) * Parsing of command-line arguments */ -static char *opt_list = "c:dD:ps:P:u:g:flR"; +static char *opt_list = "c:dD:ps:P:u:g:flRh"; static int parse_and_exit; char *bird_name; static char *use_user; @@ -625,10 +625,43 @@ static char *use_group; static int run_in_foreground = 0; static void -usage(void) +display_usage(void) { - fprintf(stderr, "Usage: %s [-c ] [-d] [-D ] [-p] [-s ] [-P ] [-u ] [-g ] [-f] [-l] [-R]\n", bird_name); - exit(1); + fprintf(stderr, "Usage: %s [--version] [--help] [-c ] [OPTIONS]\n", bird_name); +} + +static void +display_help(void) +{ + display_usage(); + + fprintf(stderr, + "\n" + "Options: \n" + " -c Use given configuration file instead\n" + " of prefix/etc/bird.conf\n" + " -d Enable debug messages and run bird in foreground\n" + " -D Log debug messages to given file instead of stderr\n" + " -f Run bird in foreground\n" + " -g Use given group ID\n" + " -h, --help Display this information\n" + " -l Look for a configuration file and a communication socket\n" + " file in the current working directory\n" + " -p Test configuration file and exit without start\n" + " -P Create a PID file with given filename\n" + " -R Apply graceful restart recovery after start\n" + " -s Use given filename for a control socket\n" + " -u Drop privileges and use given user ID\n" + " --version Display version of BIRD\n"); + + exit(0); +} + +static void +display_version(void) +{ + fprintf(stderr, "BIRD version " BIRD_VERSION "\n"); + exit(0); } static inline char * @@ -702,12 +735,9 @@ parse_args(int argc, char **argv) if (argc == 2) { if (!strcmp(argv[1], "--version")) - { - fprintf(stderr, "BIRD version " BIRD_VERSION "\n"); - exit(0); - } + display_version(); if (!strcmp(argv[1], "--help")) - usage(); + display_help(); } while ((c = getopt(argc, argv, opt_list)) >= 0) switch (c) @@ -751,11 +781,19 @@ parse_args(int argc, char **argv) case 'R': graceful_restart_recovery(); break; + case 'h': + display_help(); + break; default: - usage(); + fputc('\n', stderr); + display_usage(); + exit(1); } if (optind < argc) - usage(); + { + display_usage(); + exit(1); + } } /*