2 * Copyright (c) 2010 Nicira Networks.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "test-command-line.h"
22 #include "command-line.h"
28 test_usage(const struct command commands[])
30 const struct command *p;
32 printf("%s: an Open vSwitch test utility\n"
33 "usage: %s [OPTIONS] COMMAND [ARG...]\n\n"
35 program_name, program_name);
37 for (p = commands; p->name; p++) {
40 printf(" %s", p->name);
41 for (i = 0; i < p->min_args; i++) {
42 printf(" ARG%d", i + 1);
44 if (p->max_args == INT_MAX) {
46 } else if (p->max_args > p->min_args) {
47 for (i = p->min_args; i < p->max_args; i++) {
49 if (i == p->min_args) {
52 printf("ARG%d", i + 1);
59 printf("\nOther options:\n"
60 " -t, --timeout=SECS give up after SECS seconds\n"
61 " -h, --help display this help message\n");
65 /* Parses options for test programs that don't have any special needs.
66 * Prints --help output based on 'commands'. */
68 parse_test_options(int argc, char *argv[],
69 const struct command commands[])
71 static struct option long_options[] = {
72 {"timeout", required_argument, 0, 't'},
73 {"verbose", optional_argument, 0, 'v'},
74 {"help", no_argument, 0, 'h'},
77 char *short_options = long_options_to_short_options(long_options);
80 unsigned long int timeout;
83 c = getopt_long(argc, argv, short_options, long_options, NULL);
90 timeout = strtoul(optarg, NULL, 10);
92 ovs_fatal(0, "value %s on -t or --timeout is not at least 1",
100 test_usage(commands);
103 vlog_set_verbosity(optarg);