[ovs-dev] [PreQoS 04/13] ovs-vsctl: Add support for command options that accept arguments.
Ben Pfaff
blp at nicira.com
Thu May 27 20:33:03 UTC 2010
---
utilities/ovs-vsctl.c | 31 ++++++++++++++++++++++++++++---
1 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c
index 6702493..6fcae2b 100644
--- a/utilities/ovs-vsctl.c
+++ b/utilities/ovs-vsctl.c
@@ -306,12 +306,27 @@ parse_command(int argc, char *argv[], struct vsctl_command *command)
shash_init(&command->options);
for (i = 0; i < argc; i++) {
- if (argv[i][0] != '-') {
+ const char *option = argv[i];
+ const char *equals;
+ char *key, *value;
+
+ if (option[0] != '-') {
break;
}
- if (!shash_add_once(&command->options, argv[i], NULL)) {
+
+ equals = strchr(option, '=');
+ if (equals) {
+ key = xmemdup0(option, equals - option);
+ value = xstrdup(equals + 1);
+ } else {
+ key = xstrdup(option);
+ value = NULL;
+ }
+
+ if (shash_find(&command->options, key)) {
vsctl_fatal("'%s' option specified multiple times", argv[i]);
}
+ shash_add_nocopy(&command->options, key, value);
}
if (i == argc) {
vsctl_fatal("missing command name");
@@ -325,10 +340,20 @@ parse_command(int argc, char *argv[], struct vsctl_command *command)
SHASH_FOR_EACH (node, &command->options) {
const char *s = strstr(p->options, node->name);
int end = s ? s[strlen(node->name)] : EOF;
- if (end != ',' && end != ' ' && end != '\0') {
+
+ if (end != '=' && end != ',' && end != ' ' && end != '\0') {
vsctl_fatal("'%s' command has no '%s' option",
argv[i], node->name);
}
+ if ((end == '=') != (node->data != NULL)) {
+ if (end == '=') {
+ vsctl_fatal("missing argument to '%s' option on '%s' "
+ "command", node->name, argv[i]);
+ } else {
+ vsctl_fatal("'%s' option on '%s' does not accept an "
+ "argument", node->name, argv[i]);
+ }
+ }
}
n_arg = argc - i - 1;
--
1.7.1
More information about the dev
mailing list