2
0
mirror of https://github.com/openvswitch/ovs synced 2025-09-03 15:55:19 +00:00

command-line: New function ovs_cmdl_env_parse_all().

This function allows an environment variable to be included in
command-line parsing.  It will receive its first user in an
upcoming commit.

Signed-off-by: Aliasgar Ginwala <aginwala@ebay.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
This commit is contained in:
Aliasgar Ginwala
2019-10-25 12:33:52 -07:00
committed by Ben Pfaff
parent dee6478d4a
commit 6e26ff6337
2 changed files with 27 additions and 0 deletions

View File

@@ -19,6 +19,7 @@
#include <getopt.h> #include <getopt.h>
#include <limits.h> #include <limits.h>
#include <stdlib.h> #include <stdlib.h>
#include "svec.h"
#include "openvswitch/dynamic-string.h" #include "openvswitch/dynamic-string.h"
#include "ovs-thread.h" #include "ovs-thread.h"
#include "util.h" #include "util.h"
@@ -77,6 +78,29 @@ find_option_by_value(const struct option *options, int value)
return NULL; return NULL;
} }
/* Parses options set using environment variable. The caller specifies the
* supported options in environment variable. On success, adds the parsed
* env variables in 'argv', the number of options in 'argc', and returns argv.
* */
char **
ovs_cmdl_env_parse_all(int *argcp, char *argv[], const char *env_options)
{
ovs_assert(*argcp > 0);
struct svec args = SVEC_EMPTY_INITIALIZER;
svec_add(&args, argv[0]);
if (env_options) {
svec_parse_words(&args, env_options);
}
for (int i = 1; i < *argcp; i++) {
svec_add(&args, argv[i]);
}
svec_terminate(&args);
*argcp = args.n;
return args.names;
}
/* Parses the command-line options in 'argc' and 'argv'. The caller specifies /* Parses the command-line options in 'argc' and 'argv'. The caller specifies
* the supported options in 'options'. On success, stores the parsed options * the supported options in 'options'. On success, stores the parsed options
* in '*pop', the number of options in '*n_pop', and returns NULL. On failure, * in '*pop', the number of options in '*n_pop', and returns NULL. On failure,

View File

@@ -54,6 +54,9 @@ char *ovs_cmdl_parse_all(int argc, char *argv[], const struct option *,
struct ovs_cmdl_parsed_option **, size_t *) struct ovs_cmdl_parsed_option **, size_t *)
OVS_WARN_UNUSED_RESULT; OVS_WARN_UNUSED_RESULT;
char **ovs_cmdl_env_parse_all(int *argcp, char *argv_[],
const char *env_options);
void ovs_cmdl_print_options(const struct option *options); void ovs_cmdl_print_options(const struct option *options);
void ovs_cmdl_print_commands(const struct ovs_cmdl_command *commands); void ovs_cmdl_print_commands(const struct ovs_cmdl_command *commands);