add flag for exlusive options as program agruments
authorxrs <xrs@mail36.net>
Sat, 22 Jun 2019 20:57:55 +0000 (22:57 +0200)
committerxrs <xrs@mail36.net>
Sat, 22 Jun 2019 20:57:55 +0000 (22:57 +0200)
src/include/gnunet_getopt_lib.h
src/util/getopt.c
src/util/getopt_helpers.c

index ddeeffef4325c0007ac142531e8a4fbc4dd07ac9..17e36d889fac6d1e35ff71c983b80d4489eeae6a 100644 (file)
@@ -135,6 +135,11 @@ struct GNUNET_GETOPT_CommandLineOption
    */
   int option_mandatory;
 
+  /**
+   * Is the option exclusive?
+   */
+  int option_exclusive;
+
   /**
    * Handler for the option.
    */
@@ -424,7 +429,7 @@ GNUNET_GETOPT_option_mandatory (struct GNUNET_GETOPT_CommandLineOption opt);
  * Marker for the end of the list of options.
  */
 #define GNUNET_GETOPT_OPTION_END \
-  { '\0', NULL, NULL, NULL, 0, 0, NULL, NULL, NULL }
+  { '\0', NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL }
 
 
 /**
index 5e8571ee571c7ca8f18250fb7d01ac1921a2b641..44f6dcda226121214dad7a15f36c4883262224ca 100644 (file)
@@ -954,7 +954,16 @@ GNUNET_GETOPT_run (const char *binaryOptions,
 
   if (GNUNET_YES == cont)
   {
-    for (count = 0; NULL != allOptions[count].name; count++)
+    for (count = 0; NULL != allOptions[count].name; count++) 
+    {
+      if (allOptions[count].option_exclusive)
+      {
+        FPRINTF (stderr,
+                 _("Option `%s' can't be used with other options.\n"),
+                 allOptions[count].name);
+        cont = GNUNET_SYSERR;
+      }
+
       if ( (0 == seen[count]) &&
            (allOptions[count].option_mandatory) )
       {
@@ -963,6 +972,7 @@ GNUNET_GETOPT_run (const char *binaryOptions,
                  allOptions[count].name);
         cont = GNUNET_SYSERR;
       }
+    }
   }
   GNUNET_free (seen);
 
index 77032e5015ffac6b08a2a61a808fda510d1461c4..d6ba85733bd1a3cfb3c26e6f82028c92d44bcf81 100644 (file)
@@ -68,6 +68,7 @@ GNUNET_GETOPT_option_version (const char *version)
     .shortName =  'v',
     .name = "version",
     .description = gettext_noop("print the version number"),
+    .option_exclusive = 1,
     .processor = &print_version,
     .scls = (void *) version
   };