command-line: Add function to print all options.
[cascardo/ovs.git] / utilities / ovs-appctl.c
index a6fbebd..3d32cbd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2014 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@
 #include "timeval.h"
 #include "unixctl.h"
 #include "util.h"
+#include "vlog.h"
 
 static void usage(void);
 static const char *parse_command_line(int argc, char *argv[]);
@@ -108,14 +109,22 @@ Other options:\n\
 static const char *
 parse_command_line(int argc, char *argv[])
 {
+    enum {
+        OPT_START = UCHAR_MAX + 1,
+        VLOG_OPTION_ENUMS
+    };
     static const struct option long_options[] = {
         {"target", required_argument, NULL, 't'},
         {"execute", no_argument, NULL, 'e'},
         {"help", no_argument, NULL, 'h'},
+        {"option", no_argument, NULL, 'o'},
         {"version", no_argument, NULL, 'V'},
         {"timeout", required_argument, NULL, 'T'},
+        VLOG_LONG_OPTIONS,
         {NULL, 0, NULL, 0},
     };
+    char *short_options_ = long_options_to_short_options(long_options);
+    char *short_options = xasprintf("+%s", short_options_);
     const char *target;
     int e_options;
 
@@ -124,7 +133,7 @@ parse_command_line(int argc, char *argv[])
     for (;;) {
         int option;
 
-        option = getopt_long(argc, argv, "+t:hVe", long_options, NULL);
+        option = getopt_long(argc, argv, short_options, long_options, NULL);
         if (option == -1) {
             break;
         }
@@ -150,6 +159,10 @@ parse_command_line(int argc, char *argv[])
             usage();
             break;
 
+        case 'o':
+            print_options(long_options);
+            exit(EXIT_SUCCESS);
+
         case 'T':
             time_alarm(atoi(optarg));
             break;
@@ -158,6 +171,8 @@ parse_command_line(int argc, char *argv[])
             ovs_print_version(0, 0);
             exit(EXIT_SUCCESS);
 
+        VLOG_OPTION_HANDLERS
+
         case '?':
             exit(EXIT_FAILURE);
 
@@ -165,6 +180,8 @@ parse_command_line(int argc, char *argv[])
             OVS_NOT_REACHED();
         }
     }
+    free(short_options_);
+    free(short_options);
 
     if (optind >= argc) {
         ovs_fatal(0, "at least one non-option argument is required "