X-Git-Url: http://git.cascardo.eti.br/?a=blobdiff_plain;f=lib%2Fcommand-line.c;h=1f26c5c89810fb62f73783d8849e56809c25eccb;hb=66fa2c884fe9aee48217a76189a148bf215e0f5d;hp=cb73a25c90c46500a60a0ab79a7fda7baffc6b9b;hpb=ee4dac3bb6dcef43c51f7ddf3ad954eab4c9ed0f;p=cascardo%2Fovs.git diff --git a/lib/command-line.c b/lib/command-line.c index cb73a25c9..1f26c5c89 100644 --- a/lib/command-line.c +++ b/lib/command-line.c @@ -19,6 +19,7 @@ #include #include #include +#include "dynamic-string.h" #include "ovs-thread.h" #include "util.h" #include "vlog.h" @@ -51,6 +52,26 @@ long_options_to_short_options(const struct option options[]) return xstrdup(short_options); } +/* Given the GNU-style options in 'options', prints all options. */ +void +print_options(const struct option options[]) +{ + struct ds ds = DS_EMPTY_INITIALIZER; + + for (; options->name; options++) { + const struct option *o = options; + const char *arg = o->has_arg == required_argument ? "ARG" : "[ARG]"; + + ds_put_format(&ds, "--%s%s%s\n", o->name, o->has_arg ? "=" : "", + o->has_arg ? arg : ""); + if (o->flag == NULL && o->val > 0 && o->val <= UCHAR_MAX) { + ds_put_format(&ds, "-%c %s\n", o->val, o->has_arg ? arg : ""); + } + } + printf("%s", ds.string); + ds_destroy(&ds); +} + /* Runs the command designated by argv[0] within the command table specified by * 'commands', which must be terminated by a command whose 'name' member is a * null pointer.