diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-11-06 18:28:39 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-11-06 18:28:39 +0100 |
commit | eb9da376d76b48585b3b63b4f91903b54f7abd36 (patch) | |
tree | f58957844d6248d2df547727a4bfbd1b81c2ef97 /src/analyze/analyze.c | |
parent | 4087cb9e8fb90957d90d577e62e8ba056c2258cf (diff) |
clients: unify how we invoke getopt_long()
Among other things this makes sure we always expose a --version command
and show it in the help texts.
Diffstat (limited to 'src/analyze/analyze.c')
-rw-r--r-- | src/analyze/analyze.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index 8f965e7a8b..3b793f6664 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -1151,7 +1151,7 @@ static int set_log_level(sd_bus *bus, char **args) { return 0; } -static void help(void) { +static int help(void) { pager_open_if_enabled(); @@ -1186,11 +1186,11 @@ static void help(void) { /* When updating this list, including descriptions, apply * changes to shell-completion/bash/systemd and * shell-completion/systemd-zsh-completion.zsh too. */ + + return 0; } static int parse_argv(int argc, char *argv[]) { - int r; - enum { ARG_VERSION = 0x100, ARG_ORDER, @@ -1214,18 +1214,20 @@ static int parse_argv(int argc, char *argv[]) { { "to-pattern", required_argument, NULL, ARG_DOT_TO_PATTERN }, { "fuzz", required_argument, NULL, ARG_FUZZ }, { "no-pager", no_argument, NULL, ARG_NO_PAGER }, - { NULL, 0, NULL, 0 } + {} }; + int r, c; + assert(argc >= 0); assert(argv); - for (;;) { - switch (getopt_long(argc, argv, "hH:M:", options, NULL)) { + while ((c = getopt_long(argc, argv, "hH:M:", options, NULL)) >= 0) { + + switch (c) { case 'h': - help(); - return 0; + return help(); case ARG_VERSION: puts(PACKAGE_STRING); @@ -1280,9 +1282,6 @@ static int parse_argv(int argc, char *argv[]) { arg_host = optarg; break; - case -1: - return 1; - case '?': return -EINVAL; @@ -1290,6 +1289,8 @@ static int parse_argv(int argc, char *argv[]) { assert_not_reached("Unhandled option"); } } + + return 1; } int main(int argc, char *argv[]) { |